Sign in to follow this  
andrew1b

Trouble with FindFirstFile (Win32)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this