删除整个目录
这个是“橙子”2008年总结的删除目录的办法:
以往删除目录时,都需要先用递归删干净目录下的文件和子文件夹,这样做的时候,如果文件数量大,那么删除会非常慢于是找了个方便一点的方法,直接使用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;
未测试😀