本文实例讲述了VC判断一个文件为目录的方法,分享给大家供大家参考。具体实现方法如下:
这是一个自定义函数,用于判断一个文件是否为目录:
/**
* check whether a file is a directory
@return true if is a directory, else false(if file not exists, false)
*/
__declspec(dllexport) bool IsDirectory(const char* filename)
{
DWORD dwAttr = ::GetFileAttributes(filename); //得到文件属性
if (dwAttr == 0xFFFFFFFF) // 文件或目录不存在
return false;
else if (dwAttr&FILE_ATTRIBUTE_DIRECTORY) // 如果是目录
return true;
else
return false;
}
以下是GetFileAttribute定义,摘自msdn:
Retrieves a set of FAT file system attributes for a specified file or directory.得到FAT文件系统的文件属性
Parameters
lpFileName
The name of the file or directory.In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend