Jump to content
  • Advertisement
Sign in to follow this  
andrew1b

Trouble with FindFirstFile (Win32)

This topic is 3297 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, the following code uses to work fine (it finds all the files I'm looking for) until I try to edit any of those files (using fopen and then fclose, I'm pretty sure I close them correctly before I try to list them again). After that, the FindFirstFile stops finding my files returning INVALID_HANDLE_VALUE, as if they wouldn't exist. Here is the code:
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;

hFind = FindFirstFile("entities\*.ent", &FindFileData);

if (hFind == INVALID_HANDLE_VALUE) 
{
	std::cerr << "cFileListing::GetNumFiles - directory/files not found.\n";
	return -1;
}
int nNumFiles = 1;

while (FindNextFile(hFind, &FindFileData) != 0)
{
	nNumFiles++;
}
FindClose(hFind);

What's going on? Any clue?

Share this post


Link to post
Share on other sites
Advertisement
I tried using the absolute path and it finally worked fine. Thanks. Why does it happen only if my program reads one of the files in the path?

Share this post


Link to post
Share on other sites
Most likely something is changing the working directory. There are a few ways the working can change (e.g. calling GetOpenFileName).

In general, it's not a good idea to rely on the working directory remaining consistent throughout the life of your program. What I usually do is when the program starts up, save off the working directory and manually combine that saved working directory with any relative paths I want to use.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!