delphi 删除指定文件夹下所有文件

来源:互联网 发布:节奏大师网络被拦截 编辑:程序博客网 时间:2024/04/30 14:44

function TForm1.DeleteDirectory(NowPath: string): Boolean; // 删除整个目录
var  search: TSearchRec;  ret: integer;  key: string;begin  if NowPath[Length(NowPath)] <> '\' then    NowPath := NowPath + '\';  key := NowPath + '*.*';  ret := findFirst(key, faanyfile, search);  while ret = 0 do  begin    if ((search.Attr and fadirectory) = fadirectory) then    begin      if (search.Name <> '.') and (search.name <> '..') then        DeleteDirectory(NowPath + search.name);    end    else    begin      if ((search.Attr and fadirectory) <> fadirectory) then      begin        deletefile(NowPath + search.name);      end;    end;    ret := FindNext(search);  end;  findClose(search);  //removedir(NowPath); 如果需要删除文件夹则添加  result := True;end;
原创粉丝点击