1.既然是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_NOCONFIRMATION or FOF_SILENT; End; //execute the operation and return result. Result := (SHFileOperation(SHFileOpStruct) = 0); end; 两点注意: 1. 要应用shellapi 2. SHFileOperation(...)可以执行 copy, move, rename 和 delete 命令. file 或 folder/directory对它而言都是一个file object, 没有区别. 具体参数控制可参见 MSDN. 方法二 //删除指定的目录或文件 //Undo默认为false,即直接删除,不能undo,可以选择true,删除到回收站 function nDeleteDir(SrcDir: String;UndoMK:boolean=false):Boolean; var FS: TShFileOpStruct; begin FS.Wnd := Application.Handle; //应用程序句柄 FS.wFunc := FO_DELETE; //表示删除 FS.pFrom := PChar(SrcDir+#0#0); FS.pTo := nil; if UndoMK then FS.fFlags := FOF_NOCONFIRMATION + FOF_SILENT + FOF_ALLOWUNDO // 表示删除到回收站 else FS.fFlags := FOF_NOCONFIRMATION + FOF_SILENT; // 表示不删除到回收站 FS.lpszProgressTitle := nil; Result := (ShFileOperation(FS) = 0); End; 方法三 在 uses 中加入 ShellApi 自定义下过程 procedure TForm1.Deletedir(str:string); Var T:TSHFileOpStruct; P:String; begin...