Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Directory listing

This topic is 6768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If you read the docs on FindFirstFile, it specifies that you can use wild cards (like *, and ?). What you do is pass it a patch with a wildcard, like "C:\*". That will give you everything in the root of the C drive.

Take a look at an example program I threw together.

code:

// TestFindFirstFile.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WIN32_FIND_DATA fdFindData;
BOOL bKeepGoing = TRUE;
HANDLE hFF = ::FindFirstFile("C:\\*", &fdFindData);

::OutputDebugString(fdFindData.cFileName);
::OutputDebugString("\n");


while (::FindNextFile(hFF, &fdFindData))
{
::OutputDebugString(fdFindData.cFileName);
::OutputDebugString("\n");
}

return 0;
}


This will output every file in C:\ to the Debug window (didn't feel like getting fancy). This also returns directories. If you want to not include directories, look at the dwFileAttributes member of the WIN32_FIND_DATA structure you use.

On a side note, if you are allowing the user to pick a file or something, you might consider using the common dialogs. That might not be appropriate in your situation though...

Let me know if you need any more help via email on this.

------------------

-Kentamanos

Share this post


Link to post
Share on other sites
Advertisement
Hello,
I want to know all the files in a directory, so my program can use 'em. I currently use system("dir > listing.txt"). But this makes my screen get a dos box. I hate this view. So i thought that I might be able to get it to work with the use of spawnlp( ). But that ain't working.

Then i thought about the FindFirstFile() but this only works when you know the file names, which I don't.

Anybody know some way of either getting to know the file names in a directory or to have them put in a file and then read them.

Thnx in advance

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Maybe I should've said that I used MFC. I found another way of doing this. I made a CLIstBox...and then used the functions CListBox: ir() with 0x000000, "*.pli"

That did what I wanted to do. Thnx for this bit of code though, I give it a through look. =)

------------------
Dance with me......

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!