类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
如题
网友回答:
DWORD GetFileAttributes(
LPCTSTR lpFileName // name of file or directory
);
如果返回-1,则表示文件或者目录不存在
int IsDirectoryOrFile(CString strFileName)
{
strFileName.TrimLeft();
strFileName.TrimRight();
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(strFileName,&fd);
::FindClose(hFind);
//不存在同名的文件或文件夹
if (hFind == INVALID_HANDLE_VALUE)
{
return 0 ;
}
//判断是否为目录
else if (fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
return 2 ;
}
else
{
return 1;
}
}
文件是否存在:
BOOL IsFileValid(const CString& strFilePath)
{
DWORD dwAttribs = GetFileAttributes(strFilePath);
if (dwAttribs == ((DWORD)-1))
{
return FALSE;
}
else
{
return ((!(dwAttribs & FILE_ATTRIBUTE_DIRECTORY)) ? TRUE : FALSE);
}
}
拷贝文件:
BOOL CopyFile(
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);
BOOL PathFileExists( LPCTSTR pszPath
);
Header shlwapi.h
Import library shlwapi.lib
BOOL CopyFile(
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);