2024年3月28日发(作者:)

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;