How to check if any specific folder is empty
-
Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.
Regards, Sunil Kumar
-
Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.
Regards, Sunil Kumar
Hi Sunil, You could use the FindFirstFile Function[^] and FindNextFile Function[^] Best Wishes, -David Delaune
-
Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.
Regards, Sunil Kumar
In addition to the other replies pointing you at FindFirstFile, what is empty? Does it count as empty if there's only directories there? What if there are directories, but they have / have not got any contents themselves? You don't need to answer me, but you need to ask and answer this question for yourself. Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]
-
In addition to the other replies pointing you at FindFirstFile, what is empty? Does it count as empty if there's only directories there? What if there are directories, but they have / have not got any contents themselves? You don't need to answer me, but you need to ask and answer this question for yourself. Iain.
I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]
Yeah the case can be considered. But the directory is created by my application and the files are also created by my application. My files doesnt contain any extension. I do not understand how I can use FindFirstFile. FindFirstFile is giving me the valid handle.But FindNextFile is always returning 0, even files are present. what is the reason behind it?
Regards, Sunil Kumar
-
Yeah the case can be considered. But the directory is created by my application and the files are also created by my application. My files doesnt contain any extension. I do not understand how I can use FindFirstFile. FindFirstFile is giving me the valid handle.But FindNextFile is always returning 0, even files are present. what is the reason behind it?
Regards, Sunil Kumar
If you're using MFC you might try something like this:
BOOL DirHasFiles(CString csDir)
{
if (csDir.Right(1) != "\\")
csDir += "\\";csDir += "*.*";
BOOL bDirHasFiles = FALSE;
CFileFind ff;
BOOL bWorking = ff.FindFile(csDir);while (bWorking)
{
bWorking = ff.FindNextFile();
if (ff.IsDirectory())
{
if (ff.IsDots())
continue;
}
else
bDirHasFiles == TRUE;
}return bDirHasFiles;
}Edit: For plain WIN32, have a look here: http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx[^]
modified on Thursday, October 29, 2009 8:00 AM
-
If you're using MFC you might try something like this:
BOOL DirHasFiles(CString csDir)
{
if (csDir.Right(1) != "\\")
csDir += "\\";csDir += "*.*";
BOOL bDirHasFiles = FALSE;
CFileFind ff;
BOOL bWorking = ff.FindFile(csDir);while (bWorking)
{
bWorking = ff.FindNextFile();
if (ff.IsDirectory())
{
if (ff.IsDots())
continue;
}
else
bDirHasFiles == TRUE;
}return bDirHasFiles;
}Edit: For plain WIN32, have a look here: http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx[^]
modified on Thursday, October 29, 2009 8:00 AM
-
Hi all, I am working on VC6. I have a folder path which I have to check whether it is empty or not. Is there any API to find folder is empty? Thanks in advance.
Regards, Sunil Kumar
PathIsDirectoryEmpty