Page 1 of 1
Alphabetic NextDirectoryEntry() command?
Posted: Tue Aug 26, 2008 4:57 pm
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
Posted: Tue Aug 26, 2008 5:08 pm
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.
Posted: Tue Aug 26, 2008 5:18 pm
by Cruster
Thanks for the tips.
I hadn't spotted Gnozals PureLVSort library - that looks very promising indeed!
Posted: Tue Aug 26, 2008 5:20 pm
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.
Posted: Wed Aug 27, 2008 7:25 am
by buzzqw
i use a different approach.. just put the examine directory in Array then sort the array and polulate the list
BHH
Posted: Wed Aug 27, 2008 10:17 am
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)
Thanks to you both for your help!
Posted: Wed Aug 27, 2008 3:03 pm
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.