Yet another win32 puzzle in my quest

Started by
3 comments, last by shakazed 20 years, 10 months ago
Hi! I was wondering if there are functions that counts all the files in a folder and then returns an integer or something like that with the amount. Also I need to know if you can get the name of a file in a folder as a string. Any help appreciated. Bad Monkey Productions
Advertisement
These are Win32 functions and so probably wont work on a non windows machine.

HANDLE FindFirstFile(
LPCTSTR lpFileName, // file name
LPWIN32_FIND_DATA lpFindFileData // data buffer
);

You can use wild cards in the file name e.g. "c:\your_dir\*.*"
followed by

BOOL FindNextFile(
HANDLE hFindFile, // search handle
LPWIN32_FIND_DATA lpFindFileData // data buffer
);

until you get FALSE.

both fill in the following structure

typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA, *PWIN32_FIND_DATA;


Hope this helps
Great! Thanks man!!!
Another question popped up. Can I after I found a filename get the extension fo the file. I only want one type of files listed in the box.



Bad Monkey Productions
You would have to parse the file name for it. There are countless ways to do this. You could use strstr (or wcsstr for wide strings) or alternatively just put it in an STL string and use the appropriate find function (find_last_of I would guess as this would save you from silly file names like blah.xxx.xxx causing problems)

You mention a box, if you are wanting to do a file selection list box then there are common controls that do pretty much all of this for you.

This topic is closed to new replies.

Advertisement