up

解决方案 »

  1.   

    copyfile我说楼主,,,参数就不用写了,,查帮助就会知道的前一个是源文件的路径后一个是目标文件的路径
      

  2.   

    function CopyFileTo(const Source: string; const Destination: string): Boolean;
    再查一下帮助就知道了
      

  3.   

    CopyFile(Pchar(souce),pchar(desc),false)
      

  4.   

    yun
    例程S6_9 该例程(运行结果界面如图6 - 1 0所示)说明了如何拷贝整个目录。
    1) 通过菜单File | New Application创建一个新的工程。
    2) 参考图6 - 1 0在窗体F o r m 1中添加两个L a b e l组件、两个E d i t组件和三个B u t t o n组件,进行
    相关属性的设置。其中有两个按钮的C a p t i o n属性设置为“ . . .”,是用来给左边的E d i t组件定位
    目录的。
    3) 在U n i t 1 . p a s文件的u s e s语句中添加S h e l l A p i单元。
    4) 添加“复制( C )”按钮的O n C l i c k事件的处理过
    程如下:
    procedure TForm1.Button3Click(Sender: TO b j e c t ) ;
    v a r
    OpStruc: TSHFileOpStruct;
    FromBuf, ToBuf: Array [0..128] of Char;
    b e g i n
    FillChar( FromBuf, Sizeof(FromBuf), 0 );
    FillChar( ToBuf, Sizeof(ToBuf), 0 );
    StrPCopy( FromBuf, Pchar(Edit1.Text) );
    StrPCopy( ToBuf, Pchar(Edit2.Text) );
    // 设置O p S t r u c
    with OpStruc do
    b e g i n
    Wnd:= Handle;
    wFunc:= FO_COPY;
    pFrom:= @FromBuf;
    p To : = @ To B u f ;
    f F l a g s : = F O F _ N O C O N F I R M ATION or FOF_RENAMEONCOLLISION;
    fAnyOperationsAborted:= False;
    hNameMappings:= nil;
    l p s z P r o g r e s s Title:= nil;
    e n d ;
    下载
    图6-10 例程S6_9的运行结果界面
    if SHFileOperation( OpStruc ) = 0 then
    M e s s a g e B o x ( H a n d l e , '复制完毕。' , '信息' , M B _ O K + M B _ I C O N I N F O R M AT I O N ) ;
    e n d ;
    5) 编译、链接和运行程序,测试效果。

      

  5.   

    uses 
      shellapiProcedure TForm1.Button2Click(Sender: TObject);
    var
       SFilePath,DFilePath,SourcePath: string;
       MesString: string;
       OpStruc: TSHFileOpStruct;
       FromBuf, ToBuf: Array [0..255] of Char;
       i : Integer;
       ShouldCopy : Boolean;
       sr: TSearchRec;
       FileAttrs: Integer;
       SamListNum: Integer;
    begin
    // 准备目录拷贝
    FillChar( FromBuf, Sizeof(FromBuf), 0 );
    FillChar( ToBuf, Sizeof(ToBuf), 0 );
    // 设置OpStruc
    with OpStruc do
      begin
      Wnd:= Handle;
      wFunc:= FO_COPY;
      pFrom:= @FromBuf;
      pTo:= @ToBuf;
      fFlags:= FOF_NOCONFIRMATION;
      fAnyOperationsAborted:= False;
      hNameMappings:= nil;
      lpszProgressTitle:= nil;
      end;
    ProgressBar1.Min := 0;
    ProgressBar1.Max :=sFileListBox1.SelCount ;
    ProgressBar1.Step:= 1;
    Form1.Update ;SourcePath:=sDirectoryListBox1.Directory +'\';
    SamListNum:=sFileListBox1.Items.Count;
    for i:=0 to SamListNum-1 do
      begin
      if(sFileListBox1.Selected[i]) then
        begin
        FillChar( FromBuf, Sizeof(FromBuf), 0 );
        FillChar( ToBuf, Sizeof(ToBuf), 0 );
        SFilePath:=SourcePath+sFileListBox1.Items.Strings[i];
        StrPCopy( FromBuf, Pchar(SFilePath) );
        DFilePath:=Memo1.Lines.Strings[0]+'\'+sFileListBox1.Items.Strings[i];
        StrPCopy( ToBuf, Pchar(DFilePath) );
        //检测源路径是否存在
        {if (not DirectoryExists(SFilePath)) then
          begin
          MesString:='源路径 '+SFilePath+' 不存在。';
          MessageBox(Handle,PChar(MesString),'错误',MB_OK+MB_ICONERROR);
          Close;
          end;}
        // 检测目的路径是否存在
        ShouldCopy:=True;    if (DirectoryExists(DFilePath)) then
          begin
          MesString:='目的路径 '+DFilePath+' 已经存在。是否继续复制该目录?';
          if MessageBox(Handle,PChar(MesString),'信息',MB_YESNO+MB_ICONINFORMATION) <> IDYES then
          ShouldCopy:=False;
          end;    if ShouldCopy then
          begin
          if ShFileOperation( OpStruc ) <> 0 then
            begin
            MesString:='在复制目录'+SFilePath+'的过程中出现错误。';
            MessageBox(Handle,PChar(MesString),'错误',MB_OK+MB_ICONERROR);
            end
          else   // 将文件的属性设置为不是只读属性
            begin
            FileAttrs := faAnyFile;
              if FindFirst(DFilePath+'\*.*', FileAttrs, sr) = 0 then
              begin
                FileSetAttr(DFilePath+'\'+sr.Name, faArchive);
              end;
            while FindNext(sr) = 0 do
              begin
              FileSetAttr(DFilePath+'\'+sr.Name, faArchive);
              end;
            FindClose(sr);
            end;
          end;
          ProgressBar1.StepIt;
          end;
        if ProgressBar1.Position =ProgressBar1.Max then
          button3.Enabled :=false;
      end;
    end;
      

  6.   

    CopyFile('c:\abc.txt','d:\aaa.txt',false);
    api直接写就行了,要看在windows单元下
    第一个参数是源文件,第二个参数是目标文件,第三个参数是告诉系统文件是否存在,以便于系统决定是否要覆盖该文件.
      

  7.   

    结贴感谢82wds(Jesson) 
    同时也感谢DelphiStudy(枫)