C++文件操作——创建和删除文件夹
创建文件夹目录的相关方法:
(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
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: c++ 文件及文件夹操作(三)
- 下一篇: c++文件及文件夹操作(一)
