VC++创建指定路径的一系列文件夹
2012-07-30 11:21
309 查看
方法很简单,就是简单的调用 PathFileExists()和CreateDirectory()函数,具体过程如下:
/***********生成指定路径的文件夹**********/
CString strPath = "G:\Speech\Text\yuyin\Store";//此处可随意定义,但格式必须与所示一致,会依次创建所有的,如果已经创建好了,则不创建
CString strWPath = strPath;
CString strTemp;
if(!PathFileExists(strPath))//文件夹不存在则创建
{
strPath.TrimLeft(strPath.Left(3));
int i = strPath.Find("\\");
if(i>0)
{
strTemp = strWPath.Left(3) + strPath.Left(i);
}
else
{
strTemp = strWPath;
}
strPath.TrimLeft(strPath.Left(i));
if(!PathFileExists(strTemp))
CreateDirectory(strTemp,NULL);
while(strPath.Find("\\") == 0)
{
strPath.TrimLeft(strPath.Left(1));
int j = strPath.Find("\\");
if(j > 0)
{
strTemp = strTemp + "\\" + strPath.Left(j);
strPath.TrimLeft(strPath.Left(j));
}
else
strTemp = strTemp + "\\" + strPath;
if(!PathFileExists(strTemp))
CreateDirectory(strTemp, NULL);
}
}
/***********生成指定路径的文件夹**********/
CString strPath = "G:\Speech\Text\yuyin\Store";//此处可随意定义,但格式必须与所示一致,会依次创建所有的,如果已经创建好了,则不创建
CString strWPath = strPath;
CString strTemp;
if(!PathFileExists(strPath))//文件夹不存在则创建
{
strPath.TrimLeft(strPath.Left(3));
int i = strPath.Find("\\");
if(i>0)
{
strTemp = strWPath.Left(3) + strPath.Left(i);
}
else
{
strTemp = strWPath;
}
strPath.TrimLeft(strPath.Left(i));
if(!PathFileExists(strTemp))
CreateDirectory(strTemp,NULL);
while(strPath.Find("\\") == 0)
{
strPath.TrimLeft(strPath.Left(1));
int j = strPath.Find("\\");
if(j > 0)
{
strTemp = strTemp + "\\" + strPath.Left(j);
strPath.TrimLeft(strPath.Left(j));
}
else
strTemp = strTemp + "\\" + strPath;
if(!PathFileExists(strTemp))
CreateDirectory(strTemp, NULL);
}
}
相关文章推荐
- VC++创建指定路径的一系列文件夹
- javascript实现一个按钮,点击按钮拷贝电脑指定路径到u盘(并在U盘上创建新的文件夹)
- 日志源代码,删除指定路径所有文件夹名,并创建新的日志文件
- Qt5 实现文件复制并在指定路径下创建文件夹
- Java 创建指定文件路径下的文件夹
- VC 获取指定文件夹路径的方法小结
- C++ 指定路径文件夹存在与否查询及文件夹创建
- C++ 指定路径文件夹存在与否查询及文件夹创建
- 在磁盘指定路径,创建文件夹及文件
- 在指定路径创建文件夹, 获取EXE文件的当前目录
- VC获取指定文件夹路径
- VC 获取指定文件夹路径的方法小结
- vc++打开文件夹时,指定初始路径
- 在指定路径创建文件夹,读取图片文件,缩放图片,判断文件夹是否存在,
- vc++打开文件夹时,指定初始路径
- 创建文档库时指定文件夹(路径)
- C#编写小系统 打开指定的文件夹后,第一眼看到的文件夹的名字,创建日期,最后修改日期
- 文件夹无法删除,找不到指定路径
- JavaSE_io_根据路径逐层创建文件夹 (代码实现)
- 按照文件路径和文件名创建文件夹及下载文件的一些总结