谢谢!copyfile(’源文件’,’目标文件’,是否覆盖已存在文件);源文件如果在程序根目录,可不可以不打目录名?还有,如果选择目标目录?

解决方案 »

  1.   

    在 FileCtrl.pas 里有:function SelectDirectory(const Caption: string; const Root: WideString;
       out Directory: string): Boolean;
      

  2.   

    //我曾經寫的一個例子,共同學習
    begin
      if  not FileExists(Edit1.Text) then
      begin
        ShowMessage('Source File ('+ Edit1.Text +') not is found!');
        exit;
      end;
      if (Edit1.Text='') or (Edit2.Text='') then
      begin
        ShowMessage('FileName not is null!');
        exit;
      end;  CopyFile(PChar(Edit1.Text),PChar(Edit2.Text),True);
      if not FileExists(Edit2.Text) then
      begin
        ShowMessage('Copy File is Error!Retry or ByeBye!');
        exit;
        form2.Close;
      end;
      ShowMessage('From '+Edit1.Text +'\n'+'To '+Edit2.Text+'\n'+'Finish!' );
    end;
      

  3.   

    //有點不對
    //我曾經寫的一個例子,共同學習
    begin
      if  not FileExists(Edit1.Text) then
      begin
        ShowMessage('Source File ('+ Edit1.Text +') not is found!');
        exit;
      end;
      if (Edit1.Text='') or (Edit2.Text='') then
      begin
        ShowMessage('FileName not is null!');
        exit;
      end;  CopyFile(PChar(Edit1.Text),PChar(Edit2.Text),True);
      if not FileExists(Edit2.Text) then
      begin
        ShowMessage('Copy File is Error!Retry or ByeBye!');
        exit;
      //有點不對,不要form2.Close;這是我另有他用......
      end;
      ShowMessage('From '+Edit1.Text +'\n'+'To '+Edit2.Text+'\n'+'Finish!' );
    end;