I'm currently working on a cvi application where I need to retrieve every .wav files of the current build directory. To do so in C, I'm using windows built-in function FindFirstFIle and FindNextFile in the following function :
int listingWavFileNameInDirectory( char projectDirectory[MAX_PATHNAME_LEN], int numberOfWavFile, char **ListOfWavFile)
{
WIN32_FIND_DATA searchingFile;
HANDLE handleFind = NULL;
char workingPath[2048];
sprintf(workingPath, "%s\\*.wav*", projectDirectory);
if( (handleFind = FindFirstFile(workingPath, &searchingFile)) != INVALID_HANDLE_VALUE)
{
ListOfWavFile[0] = searchingFile.cFileName;
i = 1;
while(FindNextFile(handleFind, &searchingFile)
{
ListOfWavFile[i] = searchingFile.cFileName;
i++;
}
if( !FindClose(handleFind))
return GetLastError();
return 0;
}
else
{
return GetLastError();
}
}
This function works fine for the first wav file ( ListOfWavFile[0] has the right string), but not for other file name which are get through FindNextFile and are include ListOfWavFile[i]. ListOfWavFile[i] is actually an empty string. I just don't understand why. This is my call to the previous functions :
GetProjectDir(projectDirectory);
numberOfWavFile = countingWavFileInDirectory(projectDirectory);
listOfWavFile = malloc(numberOfWavFile * sizeof(char *));
for(int i = 0; i < numberOfWavFile; i++)
{
listOfWavFile[i] = malloc(256 * sizeof(char));
}
listingWavFileNameInDirectory(projectDirectory, numberOfWavFile, listOfWavFile);
I'm on windows 7 64-bits and my application is compiled as a 64-bits application. I try to use Wow64DisableWow64FsRedirection like said in this thread, but it doesn't work for me.
Any ideas ?