bestlong 怕失憶論壇
標題:
刪除整個資料夾
[打印本頁]
作者:
bestlong
時間:
2009-12-17 09:33
標題:
刪除整個資料夾
RmDir() 與 RemoveDirectory() 都只能刪除空資料夾,想直接刪除有包含資料的整個目錄可以用下列程式:
function DelTree(DirName: string):Boolean;
var
SHFileOpStruce: TSHFileOpStruct;
DirBuff: array[0..255] of Char;
begin
try
FillChar(SHFileOpStruce, SizeOf(SHFileOpStruce), 0);
FillChar(DirBuff, SizeOf(DirBuff), 0);
StrPCopy(DirBuff, DirName);
with SHFileOpStruce do
begin
Wnd := 0;
pFrom := @DirBuff;
wFunc := FO_DELETE;
fFlags := FOF_ALLOWUNDO;
fFlags := fFlags or FOF_NOCONFIRMATION;
fFlags := fFlags or FOF_SILENT;
end;
Result := (SHFileOperation(SHFileOpStruce)=0);
except
Result := False;
end;
end;
複製代碼
程式來源
http://delphi.about.com/cs/adptips1999/a/bltip1199_2.htm
歡迎光臨 bestlong 怕失憶論壇 (http://www.bestlong.idv.tw/)
Powered by Discuz! X1.5