我是靠谱客的博主 怕孤独毛衣,这篇文章主要介绍python 删除非空文件夹_删除文件夹(非空目录)及其中所有文件,现在分享给大家,希望可以做个参考。

//删除目录下所有文件,目录不删除

bool KbaseToXml::DeleteDirectoryFiles(char* sDirName)

{

CFileFind tempFind;

char sTempFileFind[200] ;

sprintf(sTempFileFind,"%s\*.*",sDirName);

BOOL IsFinded = tempFind.FindFile(sTempFileFind);

while (IsFinded)

{

IsFinded = tempFind.FindNextFile();

if (!tempFind.IsDots())

{

char sFoundFileName[200];

strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));

if (tempFind.IsDirectory())

{

char sTempDir[200];

sprintf(sTempDir,"%s\%s",sDirName,sFoundFileName);

DeleteDirectoryFiles(sTempDir);

}

else

{

char sTempFileName[200];

sprintf(sTempFileName,"%s\%s",sDirName,sFoundFileName);

DeleteFile(sTempFileName);

}

}

}

tempFind.Close();

/*if(!RemoveDirectory(sDirName))

{

return FALSE;

} */

return TRUE;

}

//删除目录下所有文件,目录同时删除

bool KbaseToXml::DeleteDirectory(char* sDirName)

{

CFileFind tempFind;

char sTempFileFind[200] ;

sprintf(sTempFileFind,"%s\*.*",sDirName);

BOOL IsFinded = tempFind.FindFile(sTempFileFind);

while (IsFinded)

{

IsFinded = tempFind.FindNextFile();

if (!tempFind.IsDots())

{

char sFoundFileName[200];

strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));

if (tempFind.IsDirectory())

{

char sTempDir[200];

sprintf(sTempDir,"%s\%s",sDirName,sFoundFileName);

DeleteDirectory(sTempDir);

}

else

{

char sTempFileName[200];

sprintf(sTempFileName,"%s\%s",sDirName,sFoundFileName);

DeleteFile(sTempFileName);

}

}

}

tempFind.Close();

if(!RemoveDirectory(sDirName))

{

return FALSE;

}

return TRUE;

}

阅读(3051) | 评论(0) | 转发(0) |

最后

以上就是怕孤独毛衣最近收集整理的关于python 删除非空文件夹_删除文件夹(非空目录)及其中所有文件的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(176)

评论列表共有 0 条评论

立即
投稿
返回
顶部