_chdrive odd results
Okay maybe I'm doing this completely wrong, and it does seem like a very basic question. But even using MSDN examples I believe I have it exactly the same. With some slight changes for better error checking. Well here is the code:
Now my problem is this: My program will only try to scan through the D drive (and I don't have a D drive). But will skip over A, C, E, F, etc. all the drive letters that I actually am using. Can anyone tell me why this is? ScanFolder is just a function that is recursively setup to scan through an entire directory for the search criteria with each file. Each time a new folder is found, it will call itself to scan through the new directory. But it doesn't even get that far so I haven't been able to test it.
// find all available hard drives
for( i=0 ; i<26 ; i++ )
printf("Checking %c drive.\n", i+'A');
// available drive
if( !_chdrive(i) )
// start scanning drive
printf("Scanning drive %c.\n", i+'A');
sprintf(path, "%c:\\*", i+'A');
hFind = FindFirstFile(path, &FindFileData);
if( hFind == INVALID_HANDLE_VALUE )
case 3: return(NULL); break;
printf("Cannot scan through drive %c. (%d)\n", i+'A', GetLastError());
else ScanFolder(pfFiles, path, search, hFind, FindFileData);
Contrary to most programming practices _chdrive(drive_number) is not 0 based but 1 based, so 1 = a, 2=b, and 3 = c, (and not D and your code will report) 0 is an invalid drive.
Thanks. That fixed the problem, with a couple other adjustments.