你可以使用如下的函数
RenameFile
DeleteFile
CopyFile

解决方案 »

  1.   

    procedure TForm1.ProcessFile;
    begin
      if not FileExists('C:\OMS.txt') then
      begin
        ShowMessage('指定位置没有相关文件');
        Exit;
      end else
      begin
        if CopyFile(PChar('C:\OMS.Txt'), PChar('C:\OMS_001.Txt'), True) then
        begin
          try
            DeleteFile('C:\OMS.Txt');
            RenameFile('C:\OMS_001.Txt', 'C:\OMS_002.Txt');
          except
            //
          end;
        end;
      end;
    end;Good Luck三少 :o)
      

  2.   

    直接用renamefile('oms.txt','oms_002.txt')不就行了!真的很奇怪啊。
      

  3.   

    谢谢ePing,开始时我找不到函数说明。
    别外我想问一下,我用 DeleteFile('c:\*.mme'); 执行不成功,如何解决?
      

  4.   

    你是想删除以.mme为尾缀的所有文件吗?三少 :o)
      

  5.   

    var
      Form1: TForm1;
      ExistingFileName: PChar;   
    implementationprocedure TForm1.Button1Click(Sender: TObject);
    var
      strFileName: string;       
      FindFileData: TWin32FindData;  
      SearchHandle: THandle;  
    begin
      ListView1.Items.Clear;
      if Edit2.GetTextLen = 0 then Edit2.Text:= '*.*';
      strFileName:= DirectoryListBox2.Directory + '\' + Edit2.Text;
      SetCurrentDirectory(PChar(DirectoryListBox2.Directory));
      SearchHandle:=FindFirstFile(PChar(strFileName), FindFileData);
      if (SearchHandle <> INVALID_HANDLE_VALUE) then
      repeat
        ListView1.Items.Add.Caption:=FindFileData.cFileName;
      until (FindNextFile(SearchHandle,FindFileData) = FALSE);
      Windows.FindClose(SearchHandle);
    end;procedure TForm1.SpeedButton2Click(Sender: TObject);
    var
      lpBuffer: PChar;      
      lpFilePart: PChar;    
    begin
      ListView1.Items.Clear;
      GetMem(lpBuffer,MAX_PATH);
      if Edit1.GetTextLen <> 0 then
      begin
        if (SearchPath(nil, PChar(Edit1.Text), nil, MAX_PATH, lpBuffer,
            lpFilePart) <> 0) then
            ListView1.Items.Add.Caption:=StrPas(lpBuffer)
        else
          MessageBox(0,'File was not found','Error ',MB_OK or MB_ICONWARNING);
      end;
      FreeMem(lpBuffer);
    end;procedure TForm1.Delete1Click(Sender: TObject);
    begin
      if (MessageBox (Form1.Handle, 'Are you sure you want to proceed?',
                      'Delete File or Folder', MB_OKCANCEL or
                      MB_ICONQUESTION) =ID_OK) then
      begin
        if (DeleteFile(PChar(ListView1.Selected.Caption)) = FALSE) then
          if (RemoveDirectory(PChar(ListView1.Selected.Caption)) = FALSE) then
          begin
            MessageBox(Form1.Handle, 'Error Deleting File or Folder',
                       'Delete File or Folder ',MB_ICONERROR or MB_OK);
            Exit;
          end;
        ListView1.Items.Delete(ListView1.Items.IndexOf(ListView1.Selected));
      end;
    end;procedure TForm1.ListView1Edited(Sender:TObject; Item:TListItem; var S:String);
    var
      OldName,NewName: PChar;    
    begin
      GetMem(OldName,MAX_PATH);
      GetMem(NewName,MAX_PATH);
      ExistingFileName := PChar(ListView1.Selected.Caption);
      StrPCopy(NewName,DirectoryListBox2.Directory + '\' + S);
      StrPCopy(OldName,DirectoryListBox2.Directory + '\' + ExistingFileName);
      if not MoveFile(OldName,NewName) then
       ShowMessage('Error Renaming file');
      FreeMem(OldName);
      FreeMem(NewName);
    end;上面是一个示例,当然不一定是解决你的问题的,但我想你看过以后可能对你有一些启发.good luck三少 :o)