tags:

views:

184

answers:

3

In VC++, how should I check if a directory is empty? Is there any function? I am a novice here.

+2  A: 

You could use some methods like FindFirstFile and FindNextFile to check if there are any files in the directory.

Also see this:

If the directory is empty, FindFirstFile() will only find the entry for the directory itself (".") and FindNextFile() will fail with ERROR_FILE_NOT_FOUND.

schnaader
+6  A: 

Use PathIsDirectoryEmpty method.

Canopus
+1, didn't know that this method exists.
schnaader
Neither did I, and we both thought of the answer obliquely. The question was how to check whether the folder was empty or not, not how many files it had.
Abbas
A: 

This CodeGuru article lists a CountFile function, combining FindFirstFile() and FindNextFile.

Abbas