How do you know if it's a file or directory
-
Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)
-
Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)
Test FindFirstFile() etc. WIN32_FIND_DATA.dwFileAttributes for FILE_ATTRIBUTE_DIRECTORY. Should do the trick. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
-
Given a path e.g. c:\somedir1\somedir2\file.txt how can you find out if file.txt is a directory or a file? Can't base the judgement on the extension, since there could be a directory named file.txt. :( On a side note I have an application that is using FindFirstFile and FindNextFile to enumerate all files and subdirectories in a given path. Now I want to check if this given path is a pointing to a file, so I could ShellExecute the file, instead of calling the above functions. :)
To check for directory you need to check the
dwFileAttributes
of theWIN32_FIND_DATA
structure that you pass toFindFirstFile
orFindNextFile
WIN32_FIND_DATA data;
...
// Is the found item a directory
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
...
}Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fuity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)