判断目录是否存在
来源:百度文库 编辑:神马文学网 时间:2024/04/28 07:25:11
VC判断路径是否存在
方法一:
CFileFind m_FileFind;
CString m_sFilePath = "D:\\Program Files\\Adobe\\Adobe Flash CS3";
if(!m_FileFind.FindFile(m_sFilePath)) //路径不存在则创建该路径
{
CreateDirectory(m_sFilePath,NULL);
}方法二:CString strFilePath;
strFilePath = "E:\\图像\\";
strFilePath += m_ID;
if (!SetCurrentDirectory(strFilePath))
{
CreateDirectory(strFilePath, NULL);
}
方法三:FindFirstFile()/
#define _WIN32_WINNT 0x0400#include "windows.h"int
main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind; printf ("Target file is %s.\n", argv[1]); hFind = FindFirstFile(argv[1], &FindFileData); if (hFind == INVALID_HANDLE_VALUE) {
printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
} else {
printf ("The first file found is %s\n", FindFileData.cFileName);
FindClose(hFind);
} return (0);
}方法四:FILE *fp = fopen(strPath, "r")if(fp == NULL)
{
//没有同名文件
} 方法五:
CString strPath;
strPath = "c:\\abc.dat"
if(GetFileAttributes(strPath) == 0xFFFFFFFF)
{
AfxMessageBox("文件不存在");
return;
} 。。。。。。。。。。程序如下:
CString filePath = "C:\\abc\\";
DWORD dwAttr = GetFileAttributes(filePath);
if(dwAttr==-1||(dwAttr&FILE_ATTRIBUTE_DIRECTORY)==0)//目录不存在
{
if ( !CreateDirectory(filePath, NULL) )
{
AfxMessageBox("不能创建目录");
return;
}
} 方法六: WIN32_FIND_DATA tFile;
memset(&tFile, 0, sizeof(tFile));
CString str = "d:\eeagadg\...";
if(FindFirstFile(str, &tFile) == INVALID_HANDLE_..)
不存在
方法七: int _access(
const char *path,
int mode
); 。。。。。。。。 #include
.....
char szPathName[MAX_PATH] = "C:\\ABC";
if(_access(szPathName,0) == 0)
MessageBox(NULL,"该文件夹已经存在","提示",0)
else
CreateDirectory(szPathName,NULL);————————————————————————————————————————————————————————————————————————————我在MFC程序中 用的是方法一: CString file; CFileFind fileFind; file=_T("D:\\T1\\T2"); if (!fileFind.FindFile(file))
{
CreateDirectory(file,NULL);
}因为用其他方法时,可能要加额外的头文件 所以选择了这一个参考资料:http://www.cnblogs.com/zhangpengshou/archive/2009/07/19/1526487.htmlhttp://zhidao.baidu.com/question/56430388.htmlhttp://wenda.tianya.cn/wenda/thread?tid=1235e6ad4211d93fhttp://topic.okbase.net/200704/2007040617/2954104.htmlhttp://hi.baidu.com/chinapegasus/blog/item/929e68829bd43795f703a601.htmlhttp://topic.csdn.net/t/20040618/13/3103573.htmlhttp://blog.csdn.net/yuvmen/archive/2009/09/10/4540461.aspxhttp://topic.csdn.net/t/20030912/11/2251864.html 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx
方法一:
CFileFind m_FileFind;
CString m_sFilePath = "D:\\Program Files\\Adobe\\Adobe Flash CS3";
if(!m_FileFind.FindFile(m_sFilePath)) //路径不存在则创建该路径
{
CreateDirectory(m_sFilePath,NULL);
}方法二:CString strFilePath;
strFilePath = "E:\\图像\\";
strFilePath += m_ID;
if (!SetCurrentDirectory(strFilePath))
{
CreateDirectory(strFilePath, NULL);
}
方法三:FindFirstFile()/
#define _WIN32_WINNT 0x0400#include "windows.h"int
main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind; printf ("Target file is %s.\n", argv[1]); hFind = FindFirstFile(argv[1], &FindFileData); if (hFind == INVALID_HANDLE_VALUE) {
printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
} else {
printf ("The first file found is %s\n", FindFileData.cFileName);
FindClose(hFind);
} return (0);
}方法四:FILE *fp = fopen(strPath, "r")if(fp == NULL)
{
//没有同名文件
} 方法五:
CString strPath;
strPath = "c:\\abc.dat"
if(GetFileAttributes(strPath) == 0xFFFFFFFF)
{
AfxMessageBox("文件不存在");
return;
} 。。。。。。。。。。程序如下:
CString filePath = "C:\\abc\\";
DWORD dwAttr = GetFileAttributes(filePath);
if(dwAttr==-1||(dwAttr&FILE_ATTRIBUTE_DIRECTORY)==0)//目录不存在
{
if ( !CreateDirectory(filePath, NULL) )
{
AfxMessageBox("不能创建目录");
return;
}
} 方法六: WIN32_FIND_DATA tFile;
memset(&tFile, 0, sizeof(tFile));
CString str = "d:\eeagadg\...";
if(FindFirstFile(str, &tFile) == INVALID_HANDLE_..)
不存在
方法七: int _access(
const char *path,
int mode
); 。。。。。。。。 #include
.....
char szPathName[MAX_PATH] = "C:\\ABC";
if(_access(szPathName,0) == 0)
MessageBox(NULL,"该文件夹已经存在","提示",0)
else
CreateDirectory(szPathName,NULL);————————————————————————————————————————————————————————————————————————————我在MFC程序中 用的是方法一: CString file; CFileFind fileFind; file=_T("D:\\T1\\T2"); if (!fileFind.FindFile(file))
{
CreateDirectory(file,NULL);
}因为用其他方法时,可能要加额外的头文件 所以选择了这一个参考资料:http://www.cnblogs.com/zhangpengshou/archive/2009/07/19/1526487.htmlhttp://zhidao.baidu.com/question/56430388.htmlhttp://wenda.tianya.cn/wenda/thread?tid=1235e6ad4211d93fhttp://topic.okbase.net/200704/2007040617/2954104.htmlhttp://hi.baidu.com/chinapegasus/blog/item/929e68829bd43795f703a601.htmlhttp://topic.csdn.net/t/20040618/13/3103573.htmlhttp://blog.csdn.net/yuvmen/archive/2009/09/10/4540461.aspxhttp://topic.csdn.net/t/20030912/11/2251864.html 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/shuilan0066/archive/2009/10/26/4728298.aspx
判断目录是否存在
VC判断文件目录是否存在的众多方法 - 含笑的日志 - 网易博客
Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
SQL中判断是否存在..........
用API判断文件是否存在
SMTP判断邮箱是否存在,检查email地址是否真实存在 - PHP技术文章 - PHP中...
用 PHP 内置函数 file_exists 检查文件或目录是否存在
判断数组元素是否存在重复,要求时间复杂度为O(1)
夜明珠是否真实存在?
夜明珠是否真实存在?
客观现实是否存在?
判断气血是否充足
第五维空间是否存在
神灵是否真的存在?
中国经济是否存在美国骗局?
如何判断女性是否风骚
如何判断身材是否标准?
如何判断女性是否风骚
怎么判断一个人是否说谎?
如何判断庄家是否出货
如何判断庄家是否出货
如何判断酒是否变质
判断女人是否健康的
如何判断脊椎是否健康