遞迴刪除非空資料夾

2021-04-12 19:17:09 字數 1075 閱讀 6272

cstringlist* g_psldir = null;

cstringlist* g_pslfile = null;

void main()}

//刪除資料夾

bool removedir(cstring strdir)

return false;}

//獲取系統目錄

char* getpathname()

;if ( getmodulefilename( null, szpath, max_path ) <= 0 )

int i = max_path - 1;

int j = 0;

while ( i > 2 )

if ( j == 1 )

}szpath[i+1] = '/0';

return szpath;}

//刪除檔案

bool removefile(cstring strfilename)

return false;}

//遍歷整個資料檔案目錄

int sereachpath(cstring strpath) do

strdir = strnewpath + find_data.cfilename;

g_psldir->addhead( strdir );

sereachpath( strdir );         }}

else

memset( &find_data, 0, sizeof( win32_find_data ) );

} while ( findnextfile( hfindhandle, &find_data ) ); 

findclose( hfindhandle ); 

return rt_ok;}

bool removeall(const cstring strdatapath)

for ( num=0; numgethead() ) )

g_psldir->removehead();

else

continue;}

return true;

Python遞迴刪除非空資料夾

主要就是利用遞迴思想,自己呼叫自己,建立乙個刪除資料夾的函式 傳入乙個資料夾 遍歷裡面所有的檔名 判斷 如果是檔案就直接刪除,如果遇見資料夾,就調本函式,將現在的資料夾傳給函式 在進行判斷 import os defdel dir dir name param dir name 要刪除的資料夾名字 ...

python 刪除資料夾 刪除非空資料夾

一般刪除檔案時使用os庫,然後利用os.remove path 即可完成刪除,如果刪除空資料夾則可使用os.removedirs path 即可,但是如果需要刪除整個資料夾,且資料夾非空時使用os.removedirs path 就會報錯了,此時可以使用shutil庫,該庫為python內建庫,是乙...

cmd強制刪除非空資料夾

e program anewlabor frontend rd s q node modulesrd 刪除資料夾 鍵入到要刪除的目錄下 s刪除目錄及目錄下的所有子目錄和檔案 q 可取消刪除操作時的系統確認就直接刪除 e program anewlabor frontend rd s q node m...