将一Edit显示的路径中的文件,备份至另一Edit显示的路径处?最好有代码。

解决方案 »

  1.   

    path1:=edit1.text;  //原路徑
      path2:=edit2.text;  //備份路徑
      try
        copyfile(Pchar(v_path1),Pchar(path2),False);
      except
        showmessage('error');
      end;
      

  2.   

    拷贝目录树!!!
    {拷贝目录!注意:sDirName, sToDirName 一定要用绝对路径 }
    function DoCopyDir(sDirName:String;
        sToDirName:String; overwrites:Boolean):Boolean;
    var
        hFindFile:Cardinal;
        t,tfile:String;
        sCurDir:String[255];
        FindFileData:WIN32_FIND_DATA;
    begin
    //先保存当前目录
        sCurDir:=GetCurrentDir;
        ChDir(sDirName);
        hFindFile:=FindFirstFile('*.*',FindFileData);
        if hFindFile <> INVALID_HANDLE_VALUE then
        begin
            if not DirectoryExists(sToDirName) then
                ForceDirectories(sToDirName);
            repeat
                tfile:=FindFileData.cFileName;
                if (tfile='.') or (tfile='..') then
                Continue;
                if FindFileData.dwFileAttributes= FILE_ATTRIBUTE_DIRECTORY then
                begin
                    t:=sToDirName+'\'+tfile;
                    if not DirectoryExists(t) then
                    ForceDirectories(t);
                    if sDirName[Length(sDirName)]<>'\' then
                    DoCopyDir(sDirName+'\'+tfile, t, overwrites)
                    else
                    DoCopyDir(sDirName+tfile,sToDirName+tfile,overwrites);
                end
                else
                begin
                    t:=sToDirName+'\'+tFile;
                    CopyFile(PChar(tfile),PChar(t),not overwrites);
                end;
            until FindNextFile(hFindFile,FindFileData)=false;
            windows.FindClose(hFindFile);
        end
        else
        begin
            ChDir(sCurDir);
            result:=false;
            exit;
        end;
        //回到原来的目录下
        ChDir(sCurDir);
        result:=true;
    end;function CopyDir(sDirName:String;
        sToDirName:string; overwrites:Boolean):Boolean;
    begin
        if Length(sDirName)<=0 then exit;    Result:=DoCopyDir(sDirName,sToDirName,overwrites);
    end;
      

  3.   

    copyfile(edit1.txt+'123.dbf',edit2.txt+'456.dbf',false)
      

  4.   

    var
    str,str1:string;
    OpStruc: TSHFileOpStruct;
    FromBuf, ToBuf: Array [0..128] of Char;
    direc:string;
    begin
         try
            direc:='c:\temp';
            if not DirectoryExists(direc)
            then ForceDirectories(direc);
            str:='a.db';
            deletefile(direc+'\'+str);
            if not fileExists(direc+'\'+str) then
            begin
                 FillChar( FromBuf, Sizeof(FromBuf), 0 );
                 FillChar( ToBuf, Sizeof(ToBuf), 0 );             StrPCopy( FromBuf, Pchar(frm_directory+'\'+frm_filename) );
                 StrPCopy( ToBuf, Pchar(direc) );
                 // 设置OpStruc
                 with OpStruc do
                 begin
                      Wnd:= Handle;
                      wFunc:= FO_COPY;
                      pFrom:= @FromBuf;
                      pTo:=@ToBuf;
                      fFlags:=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
                      fAnyOperationsAborted:= False;
                      hNameMappings:= nil;
                      lpszProgressTitle:= nil;
                 end;
                 if ShFileOperation( OpStruc ) = 0 then  //复制文件成功
                 begin
                         str1:=extractfilename(frm_directory+'\'+frm_filename);
                         ChDir(direc);
                       //  str1:=copy(str1,1,8)+'.db';
                         if  renamefile(str1,str) then    //备份文件该名成功
                             ;             end;
            end;
      except
            exit;
      end;
      

  5.   

    copyfile(Pchar(edit1.text+db),Pchar(edit2.text+db),False);
    不过它不能备份当前更新数据