C語言實現遞迴刪除資料夾

2021-07-03 23:32:43 字數 800 閱讀 2146

使用rmdir函式只能刪除空資料夾,對於非空資料夾就無能為力了,這裡給出乙個實現,用來刪除整個資料夾

0、儲存當前絕對路徑

1、開啟要刪除的資料夾

2、進入要刪除的資料夾

3、讀資料夾

4、如果讀到的是資料夾,將當前讀到的資料夾名稱作為引數返回0遞迴

5、如果不為資料夾呼叫remove刪除

6、返回並呼叫rmdir刪除相應資料夾

下面給**

#include

#include

#include

#include

#include

#include

#include

void error_quit(const char *msg)

void change_path(const char *path)

void rm_dir(const char *path)

if(remove(dirp->d_name)==-1)

error_quit("remove");

printf("rm %s successed . . .\n",dirp->d_name);

}closedir(dir);

change_path(p);

if(rmdir(path)==-1)

error_quit("rmdir");

printf("rm %s successed . . .\n",path);

}int main(int argc,char **argv)

if (argc < 2)

C 語言實現建立,刪除和移動資料夾

本文採用c 語言實現建立,刪除和移動資料夾,如下 使用directory類和directoryinfo類 一 建立資料夾 tryelse catch exception ee 二 刪除資料夾 tryelse catch exception ee 三 移動資料夾 源資料夾和目標資料夾要求存在於同乙個硬...

遞迴刪除資料夾

只能刪除目錄內的所有檔案,目錄內的目錄未刪除。因為當時os.rmdir 不知道加在哪,好像哪都不對,有知道的請告訴我。import os from os import path def diy remove the path if path.exists the path if path.isdir...

遞迴刪除資料夾

方法名稱 deletefolder 方法描述 遞迴刪除目錄下的所有檔案及子目錄下所有檔案 param dir 將要刪除的檔案目錄 return boolean returns true if all deletions were successful.if a deletion fails,the ...