WriteDirectory() sporadically failed. My computer is running windows 7/32. I could fix the problem by checking the result of FindFirstFile(). This does not make sense, because FindClose() should also work with invalid handles, however this fix works:
fFile = FindFirstFile(cs_directory_to_create,&fileinfo;);
if (INVALID_HANDLE_VALUE != fFile)
You should change the line
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
to if ((fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
The problem is that if the directory has more than just the
directory attribute set the check will fail. I found this
out by turning off the "Allow Indexing Service to index
this disk for fast file searching" under properties for the
drive in Windows XP. This added the attribute
thus causing the checks for the directory to fail.
Although recursive logic might be simpler to code, recursive functions use up a lot more stack space. So, the non-recursive original code might be more useful, especially if I am creating very deeply nested paths (4K or greater).
However, I agree using the ImageHlp API is probably the best.