Jump to content
  • Advertisement


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


Yet another win32 puzzle in my quest

This topic is 5572 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

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

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
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 ];

Hope this helps

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!