C++文件操作——创建和删除文件夹

来源:互联网 发布:淘宝老客户营销短信 编辑:程序博客网 时间:2024/05/22 09:01

创建文件夹目录的相关方法:

(1).采用CreateDirectory函数

CString strPath;   GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);   strPath.ReleaseBuffer();   int pos = strPath.ReverseFind('\\');   strPath = strPath.Left(pos);  CString strLogPath;strLogPath = strPath + L"\\Log";if (!PathIsDirectory(strLogPath)){CreateDirectory(strLogPath,0);}
(2).采用C运行库函数int mkdir()和int _mkdir()
//声明标识符USES_CONVERSION;//调用函数,T2A和W2A均支持ATL和MFC中的字符转换char * pLogPath = T2A(strLogPath);_mkdir(pLogPath);
(3).调用system命令md
char chLogPath[MAX_PATH]="";sprintf_s(chLogPath,sizeof(chLogPath),"md %s",pLogPath);system(chLogPath);


删除文件夹目录的相关方法。

依据上述创建方法,同样有对应的三种删除方法。

(1).调用调用Windows API函数 RemoveDirectory()

(2).调用C运行库函数int rmdir()和int _rmdir()

(3).调用system命令rd

原创粉丝点击