DeleteFile(ExtractFileDir(Application.Exename)+'\Files\070409.txt');
  对单个文件删除可以实现,但我想删除类似 有文件名 0704 的文件,怎么实现呢?

解决方案 »

  1.   

    用ShellExeCute调用DOS命令DEL,可以用通配符的。要不你就FindFirst、FindNext这样找到一个删一个。
      

  2.   

    不好意思,ShellExecute和winexec好象都不行....
      

  3.   

    一种方法就是用我在上面说的FindFirst + FindNext 找一个删一个,另外,我给你找了一个函数,试了可以用:function DeleteFileEx(const AFileSrc: string): boolean;
    var
      fo : TSHFILEOPSTRUCT;
    begin
      FillChar(fo, SizeOf(fo), 0);
      with fo do
        begin
        Wnd := 0;
        wFunc := FO_DELETE;
        pFrom := PChar(AFileSrc);
        fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
        end;
      Result := (SHFileOperation(fo) = 0);
    end;函数出自:http://www.80diy.com/home/20011030/10/347282.html
      

  4.   

    我还想用个for语句 循环将一个一个文件删除呢
    function   DelFiles(FilePath:String): Boolean;
    var
      Find: TSearchRec;
    begin
      if  (FindFirst(FilePath, faAnyFile, Find) = 0) then
      begin
        if Pos(FilePath,Find.Name)>0 then
          DeleteFile(FilePath+'\'+Find.Name);   
      end;
    end;
    谢谢 lihuasoft(一九七五) 你的思路我接受:)
      

  5.   

    function DelFiles(FilePath,FileName:String): Boolean; //FilePath:='C:\temp';FileName:='temp';
    var
      Find: TSearchRec;
    begin
      SetCurrentDir(FilePath);
      if FindFirst('*',faArchive,Find) = 0 then
      begin
        repeat
        if Pos(FileName,Find.Name)>0 then
          DeleteFile(FilePath +'\' + Find.Name)
        until FindNext(Find) <> 0;
         FindClose(Find);
      end;
    end;//这样就实现了