Alphabetic NextDirectoryEntry() command?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Cruster
User
User
Posts: 96
Joined: Fri Jan 23, 2004 12:05 am

Alphabetic NextDirectoryEntry() command?

Post by Cruster »

Hi all,
I'd like to display the content of a directory alphabetically.
The NextDirectoryEntry(#Directory) command obtains the entries by (I think) date order? Is there an easy way to alter this so that it instead displays alphabetically?

Code: Select all

entries = 0
	If ExamineDirectory(#Directory, Directory$, "*.msg") ;// Only look for .msg files
		While NextDirectoryEntry(#Directory)				
		entries = entries + 1						           ;// Count the total of .msg files
		Filename$ = DirectoryEntryName(#Directory)        ;// Get the Filename 
		AddGadgetItem(#List, -1,Filename$)                ;// Place it into the list window
		Wend
		FinishDirectory(#Directory)
	EndIf	
PureBasic 4.3 registered user
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

I don't think you can do that with the command as it is, but what you can do is take what it gives you and do a seperate sort for alphabetical order then display the sorted list from your sort routine.

I think there are a few libraries also like Gnozal's PureLVSORT library, and maybe some source in the forums you can adapt/use like at http://www.purebasic.fr/english/viewtop ... abetically ...and...http://www.purebasic.fr/english/viewtop ... abetically

or....place the output into an array and use SortArray.
User avatar
Cruster
User
User
Posts: 96
Joined: Fri Jan 23, 2004 12:05 am

Post by Cruster »

Thanks for the tips. :)
I hadn't spotted Gnozals PureLVSort library - that looks very promising indeed!
PureBasic 4.3 registered user
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Yeah, I like Gnozals PureLVSort library, use it myself. It is kinda big to include if your project is very small, but i perfer it once I got used to it.
buzzqw
Enthusiast
Enthusiast
Posts: 116
Joined: Sat Aug 27, 2005 10:13 pm
Location: Italy
Contact:

Post by buzzqw »

i use a different approach.. just put the examine directory in Array then sort the array and polulate the list

BHH
User avatar
Cruster
User
User
Posts: 96
Joined: Fri Jan 23, 2004 12:05 am

Post by Cruster »

buzzqw wrote:i use a different approach.. just put the examine directory in Array then sort the array and polulate the list

BHH
Thanks, you're right :) I'd got hung up on the order which the examine directory was giving me the filenames and I hadn't made the connection that this output could be sorted or manipulated before it was displayed in a List Gadget (seems so obvious now) :oops:

Thanks to you both for your help!
PureBasic 4.3 registered user
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

No need for the wonderful PureLVSort library here.

Just use the flags for the ExplorerListGadget and process the contents as desired.

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "ExplorerListGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ExplorerListGadget(0, 10, 10, 380, 180, "C:\*.*", #PB_Explorer_NoDirectoryChange|#PB_Explorer_NoParentFolder|#PB_Explorer_NoFolders|#PB_Explorer_AutoSort)
  ; Optionally, remove unwanted columns and change the width of the first column
  RemoveGadgetColumn(0, 3)
  RemoveGadgetColumn(0, 2)
  RemoveGadgetColumn(0, 1)
  SetGadgetItemAttribute(0, 0, #PB_Explorer_ColumnWidth, 359, 0)
  ; ----------------------------------------------------------------------------
  ; Process the list as desired here
  ; ----------------------------------------------------------------------------
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf 
The above code automatically sorts on file name. You could have the ExplorerListGadget sort on size, file type, or date modified as you wish. You may even use this with the gadget hidden.
Post Reply