生命之风的低语
Whispers in the Wind of Life.

文件操作

2026-02-28 17:30:27

文件操作 - 删除指定文件夹目录中全部文件(包含文件夹)

1 // 删除指定文件夹目录中全部文件(包含文件夹)

2 void DeleteDirectory(CString strDir)

3 {

4 // 首先删除文件及子文件夹

5 CFileFind ff;

6 BOOL bFound = ff.FindFile(strDir+L"\\*", 0);

7 while(bFound)

8 {

9 bFound = ff.FindNextFile();

10 if(ff.GetFileName()=="."||ff.GetFileName()=="..")

11 continue;

12 // 去掉文件(夹)只读等属性

13 SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);

14 if(ff.IsDirectory())

15 {

16 // 递归删除子文件夹

17 DeleteDirectory(ff.GetFilePath());

18 RemoveDirectory(ff.GetFilePath());

19 }

20 else

21 {

22 // 删除文件

23 DeleteFile(ff.GetFilePath());

24 }

25 }

26 ff.Close();

27

28 // 然后删除该文件夹

29 RemoveDirectory(strDir);

30 }

posted @

2016-04-27 17:09

C/C++/Python/Java

阅读(2957)

评论(0)

收藏

举报