#include <stdio.h>
void main()
{
char tmp[28]={0},c[]="foldername";
sprintf(tmp,"mkdir %s",c);
system(tmp);
}
//////////////////////////////////////////////////////////////////////////
SYSTEMTIME sys;
GetLocalTime( &sys );
CString strFilePath;//文件路径
CString strFolder;//文件夹名称
CString strTemp;
strTemp.Format("%d", sys.wYear);
strFolder = strTemp;
if(!PathFileExists(strFolder))//文件夹不存在则创建
{
CreateDirectory(strFolder,NULL);
}
strTemp.Format("\\%d", sys.wMonth);
strFolder += strTemp;
if(!PathFileExists(strFolder))//文件夹不存在则创建
{
CreateDirectory(strFolder,NULL);
}
strTemp.Format("\\%d", sys.wDay);
strFolder += strTemp;
if(!PathFileExists(strFolder))//文件夹不存在则创建
{
CreateDirectory(strFolder,NULL);
}
方法很简单,就是简单的调用 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);
}
}