删除整个目录
以往删除目录时,都需要先用递归删干净目录下的文件和子文件夹,这样做的时候,如果文件数量大,那么删除会非常慢;
于是找了个方便一点的方法,直接使用API将目录删除:
于是找了个方便一点的方法,直接使用API将目录删除:
代码如下:
function DelDirectory(const Source: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(Source + #0);
pTo := #0#0;
fFlags := FOF_NOCONFIRMATION + FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_DELETE;
pFrom := PChar(Source + #0);
pTo := #0#0;
fFlags := FOF_NOCONFIRMATION + FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;
转载于:https://blog.51cto.com/65517285/79754