GetLogicalFolders?
Moderator: Moderators
GetLogicalFolders?
Obviously there is no such Windows API function, but I already use the get logical drives functions to get drive info, however I don't know how to get a folder or file list. Which function can I use to get a folder and a file list? I would use OPENFILENAME and GetOpenFileName, but I am creating my own custom box.
Look for "dirent" by Kevlin Henney. It implements a subset of the POSIX opendir(), readdir(), and closedir() functionality in Windows. I used it in a ROM builder for SMSAdvance.
Which graphics API are you using? Allegro? SDL? Straight DirectX?
Which graphics API are you using? Allegro? SDL? Straight DirectX?
File Management reference:
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
Example:
http://www.thescripts.com/forum/post2129361-4.html
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx
Example:
http://www.thescripts.com/forum/post2129361-4.html
Sorry for misspellings, I'm from Sweden ^^
What you want to do is walk the directory tree, making a list. The algorithm is roughly as follows:
What FindxFile lets you do is "For each file or folder inside the folder". "Clear" and "add" are methods of your programming environment's list container, whether it be an array list or a linked list, or whether it be whether it be a C++ STL list, a list in the standard library of any other language, or a custom list. The rest is recursion.
Code: Select all
To walk a tree:
Clear the list of folders and the list of files
Walk the folder at the root of the tree
To walk a folder:
For each file or folder inside the folder:
If the found object is a folder:
Add the found object to the list of folders
Walk the found object
Else:
If the found object is a file of a desirable type:
Add the found object to the list of files
I wouldn't recommend trying to distinguish folders from files purely based on their names. In FAT and NTFS, folders are allowed to have a dot in their names, and folders are even allowed to have names ending in .nes.WedNESday wrote:I've done it now. FindFirstFile("*."... for the folders
EDIT: I looked up FindFirstFile(), and it seems that family of functions puts the result in a struct called WIN32_FIND_DATA, which appears to be Win32's analog of POSIX's struct stat. For each entry that is a folder, (st->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) should be nonzero.