GetLogicalFolders?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

GetLogicalFolders?

Post by WedNESday » Sat Mar 29, 2008 9:38 am

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.

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat Mar 29, 2008 12:13 pm

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?

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Sat Mar 29, 2008 12:35 pm

No, that doesn't seem to be what I'm looking for. I'm using the Windows API, but I don't mind using C++.

User avatar
dXtr
Posts: 375
Joined: Tue Sep 21, 2004 12:11 am
Location: Karlshamn (Sweden)

Post by dXtr » Sat Mar 29, 2008 12:40 pm

Sorry for misspellings, I'm from Sweden ^^

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sat Mar 29, 2008 1:18 pm

WedNESday wrote:No, that doesn't seem to be what I'm looking for.
Then could you please explain what you are looking for?

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Sat Mar 29, 2008 4:09 pm

Ok, I have a list of drives, and I can get a list of *.whatever files in a specific directory using FindxFile. What I need to be able to do is get a list of directories in a drive.

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Mar 30, 2008 5:07 am

Do you want a list of folders/directories in the current folder, or a list of all folders at all levels of a drive, recursively?

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Sun Mar 30, 2008 6:41 am

I need a list of all folders in a drive and then in the folders themselves. So both.

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Sun Mar 30, 2008 8:01 am

What you want to do is walk the directory tree, making a list. The algorithm is roughly as follows:

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
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.

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Mon Mar 31, 2008 5:41 am

I've done it now. FindFirstFile("*."... for the folders and FindFirstFile("*.nes"... for the files. Thanks ;).

tepples
Posts: 22278
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples » Mon Mar 31, 2008 6:13 am

WedNESday wrote:I've done it now. FindFirstFile("*."... for the folders
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.

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.

Marty
Posts: 40
Joined: Fri Nov 12, 2004 5:02 am

Post by Marty » Mon Mar 31, 2008 6:22 am

WIN32_FIND_DATA::dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY can be used to check whether it's a directory or not.

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Sun Apr 27, 2008 9:44 am

Can FindFirstFile/FindNextFile have multiple file filters? (*.bin; *.nes etc.)

User avatar
Dwedit
Posts: 4408
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit » Sun Apr 27, 2008 10:34 am

I just ended up using Boost
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

WedNESday
Posts: 1236
Joined: Thu Sep 15, 2005 9:23 am
Location: Berlin, Germany
Contact:

Post by WedNESday » Sun Apr 27, 2008 1:50 pm

Dwedit wrote:I just ended up using Boost
What?

Post Reply