给定一个目录名或文件名,如何判断其是否存在?在线等 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BOOL FileExists(LPCTSTR lpszFileName){ WIN32_FIND_DATA wfd; BOOL bRet; HANDLE hFind; hFind = FindFirstFile(lpszFileName, &wfd); bRet = hFind != INVALID_HANDLE_VALUE; FindClose(hFind); return bRet;} 你可以用CFileFind类去查找,不过我一般用CFile去打开文件,成功则文件存在,否则不存在CFile file;if(file.Open(filename, CFile::modeRead)){ //file exist file.Close();}else{ //file not exist}当然如果该文件被别的程序非共享打开的话,文件打开也会失败 BOOL FileExists(LPCTSTR lpszFileName){ WIN32_FIND_DATA wfd; BOOL bRet; HANDLE hFind; hFind = FindFirstFile(lpszFileName, &wfd); bRet = hFind != INVALID_HANDLE_VALUE; FindClose(hFind); return bRet;}这个能判断目录吗? int check_path(char *path){ if(_chdir(path) == 0) return 0; // dir is exist. if(fopen(path,"r") != 0) return 0; // file is exist. return -1; // path is not exist.} 文档类给视类发消息 vc输出文本 怎样能同时利用vc6/2008的符号? 紧急求教 求助:VC中组合框控件中下拉的内容在哪里加载? VFW 中结构 AVICOMPRESSOPTIONS的参数lpParms是什么意思?怎么赋值? MFC初学者用哪本书比较好? 大家好,为了大家更好的学习VC++、c# 、OpenGL,加OpenGL技术群 急.属性框简单问题 VC怎么对 INT 13端口进行操作啊! DeviceIoControl行吗?? 如何用VC获得汉字的Unicode码? VB转VC问题:
{
WIN32_FIND_DATA wfd;
BOOL bRet;
HANDLE hFind;
hFind = FindFirstFile(lpszFileName, &wfd);
bRet = hFind != INVALID_HANDLE_VALUE;
FindClose(hFind);
return bRet;
}
if(file.Open(filename, CFile::modeRead))
{
//file exist
file.Close();
}
else
{
//file not exist
}
当然如果该文件被别的程序非共享打开的话,文件打开也会失败
{
WIN32_FIND_DATA wfd;
BOOL bRet;
HANDLE hFind;
hFind = FindFirstFile(lpszFileName, &wfd);
bRet = hFind != INVALID_HANDLE_VALUE;
FindClose(hFind);
return bRet;
}
这个能判断目录吗?
{
if(_chdir(path) == 0)
return 0; // dir is exist.
if(fopen(path,"r") != 0)
return 0; // file is exist.
return -1; // path is not exist.
}