[問題] 移除空資料夾失敗

看板C_and_CPP作者 (evilkiss)時間12年前 (2011/11/23 19:28), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
我是在BCB上開發 在寫一個刪除整個資料夾的func()時 發現我寫的func只能在資料夾A下沒有其他資料夾的case 才會在刪除所有資料夾A中的檔案後 把資料夾A刪除 只要資料夾A裡面有其他資料夾 removedirectory 就return false 程式沒關 重覆執行func沒有用 要不斷的關掉執行檔 再啟動 才能把資料夾A刪除 不知道我犯了什麼錯誤 可以請大家指點一下嗎? 以下是我的func void TForm1::My_DeleteFolder(String path, String name) { String Target=path+name+"/"; HANDLE hFindFile; TSearchRec sr; WIN32_FIND_DATA FindFileData; AnsiString NowPath=Target+"*.*"; hFindFile = FindFirstFile(NowPath.c_str(), &FindFileData); if(hFindFile==INVALID_HANDLE_VALUE) { String sDone=path+name; RemoveDirectory(sDone.c_str()); } else { FindFirst(NowPath.c_str(), faAnyFile, sr); if(sr.Name=="." || sr.Name=="..") { } bool bResult = false; while( !bResult) { if (!FindNextFile(hFindFile, &FindFileData)) { bResult = true; } else { FindNext(sr); if(sr.Name=="." || sr.Name=="..") continue; else if(sr.Attr&faDirectory) { String temp_name=(String)sr.Name; My_DeleteFolder(Target,temp_name); } else { String temp_name=(String)sr.Name; My_DeleteFile(Target,temp_name); } } } String sDone=path+name; // FindClose(hFindFile); 加了反而所有資料夾都不會被刪除 bool tempa=RemoveDirectory(sDone.c_str()); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.72.92.44 ※ 編輯: evilkiss 來自: 211.72.92.44 (11/23 19:30)

11/23 20:13, , 1F
原來hFindFile sr都要close....
11/23 20:13, 1F
※ 編輯: evilkiss 來自: 211.72.92.44 (11/23 20:13)
文章代碼(AID): #1EpDZpZM (C_and_CPP)