Directory listing

Started by
1 comment, last by CJ 24 years, 5 months ago
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

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

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

This topic is closed to new replies.

Advertisement