文件拷贝的函数怎么写?filecopy?最好是举例说明

解决方案 »

  1.   

    Copies the source file to the destination file.
    function CopyFileTo(const Source: string; const Destination: string): Boolean;Parametersconst Source: stringSource file name.
    const Destination: stringDestination file name.
    ReturnsBoolean - True if the file is copied, False on error.
    DescriptionCopyFileTo is a function used to copy the file specified in Source to the file specified in 
    Destination.
    CopyFileTo will return False if the file in Destination already exists.
    CopyFileTo encapsulates the platform-specific calls needed to perform the file copy operation. On the Windows platform, this is the Win32 API function CopyFile. On the Linux platform, CopyFileTo uses a TFileStream instance to create the destination file.
      

  2.   

    if CopyFile('D:\160034.swf','E:\a.swf',true) then ShowMessage('ok');
      

  3.   

    procedure NetFileCopy(SourceFile,MoveToFile:string;P:TRzProgressBar);
    var
      FromF, ToF: file;
      NumRead, NumWritten: Integer;
      Buf: array[1..2048] of Char;
    begin
        AssignFile(FromF, MoveToFile);
        Reset(FromF, 1); { Record size = 1 }    AssignFile(ToF,SourceFile); { Open output file }
        Rewrite(ToF, 1); { Record size = 1 }    P.PartsComplete:=0;
        P.TotalParts:=sizeof(FromF);
        repeat
            BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
            BlockWrite(ToF, Buf, NumRead, NumWritten);
            P.IncPartsByOne;
        until (NumRead = 0) or (NumWritten <> NumRead);
        CloseFile(FromF);
        CloseFile(ToF);
        P.PartsComplete:=0;
    end;
      

  4.   

    procedure ShellFileOperation(fromFile: string; toFile: string; Flags: Integer);
    {复制或者移动文件
    flags取值:
    FO_COPY:复制操作
    FO_MOVE:移动操作
    }
    var
      shellinfo: TSHFileOpStructA;
    begin
      with shellinfo do
      begin
        wnd   := Application.Handle;
        wFunc := Flags;
        pFrom := PChar(fromFile);
        pTo   := PChar(toFile);
      end;
      SHFileOperation(shellinfo);
    end;