既然是windows 平台上, 就用shell API 吧
下面是一个例子: PHP 代码: uses ShellAPI; function DeleteDirectory(const sDir : string) : Boolean; var SHFileOpStruct : TSHFileOpStruct; FromBuf : Array [0
255] of Char; ToBuf : Array [0
255] of Char; begin //make sure the target directory existing if not DirectoryExists(sDir) then begin Result := False; exit; end; //Initialize SHFileOpStruct
Fillchar(SHFileOpStruct, Sizeof(SHFileOpStruct), 0); FillChar(FromBuf, Sizeof(FromBuf), 0); FillChar(ToBuf, Sizeof(ToBuf), 0); StrPCopy(FromBuf, sDir); StrPCopy(ToBuf, ''); //Delete directory and all its subdirectory as well as files
//fill out the shell file operation struct
With SHFileOpStruct Do Begin Wnd := 0; wFunc := FO_DELETE; pFrom := @FromBuf; pTo := @ToBuf; fFlags := FOF_ALLOWUNDO; fFlags := FOF_NOCONFIR