DELPHI程序放在C盘下,运行程序,程序要从服务器上COPY一个文件到C盘程序所在的地方,请问如何实现?
请说的详细一点儿。谢谢。
如何代码请贴出。

解决方案 »

  1.   

    Function FileMove(SourceFile, DestinationFile: String): Boolean;Var  DestFileName: String;  FS,FD: TextFile;Begin  If Not IsFile(SourceFile) Then  Begin    Result := False;    Exit;  End  Else  Begin    AssignFile(FS, SourceFile);    Reset(FS);    CloseFile(FS);  End;  If IsFile(DestinationFile) Then  Begin    AssignFile(FD, SourceFile);    Reset(FD);    CloseFile(FD);    If Length(FileExt(DestinationFile)) > 0 Then    Begin      DestFileName := FileName(DestinationFile)+'.'+FileExt(DestinationFile);    End    Else    Begin      DestFileName := FileName(DestinationFile);    End;    If Not DeleteFiles(FilePath(DestinationFile),DestFileName) Then    Begin      Result := False;      Exit;    End;  End;  Result := ReNameFile(SourceFile,DestinationFile);End;
      

  2.   

    The CopyFile function copies an existing file to a new file. BOOL CopyFile(    LPCTSTR  lpExistingFileName, // address of name of an existing file 
        LPCTSTR  lpNewFileName, // address of filename to copy to 
        BOOL  bFailIfExists  // flag for operation if file exists 
       );
    ParameterslpExistingFileNamePoints to a null-terminated string that specifies the name of an existing file. lpNewFileNamePoints to a null-terminated string that specifies the name of the new file. bFailIfExistsSpecifies how this operation is to proceed if a file of the same name as 
    that specified by lpNewFileName already exists. If this parameter is TRUE 
    and the new file already exists, the function fails. If this parameter is 
    FALSE and the new file already exists, the function overwrites the existing
     file and succeeds. Return ValueIf the function succeeds, the return value is TRUE.
    If the function fails, the return value is FALSE. To get extended error 
    information, call GetLastError.
      

  3.   

    copyfile(pchar('f:\123.dbf'),pchar(c:\123.dbf'),false);
      

  4.   

    CopyFile('\\服务器IP或机名\共享日录\文件名',Pchar(ExtractFilePath(Application.ExeName)+'文件名'),true);你的机子要有权限访问服务器共享,也就是网上邻居可以访问服务器机子。如果发生错误,先用网上邻居可以访问服务器机子,然后再试.
      

  5.   

    如果文件名一样要覆盖怎么办?怎么退出当然的文件再COPY?
      

  6.   

    问错了,是要COPY的文件和当然用行的文件同名,要先退出,再COPY,再运行COPY过来的新文件怎么做?
      

  7.   

    CopyFile(pchar(FormFile),pchar(ToFile),false)
    具体的可以看看Delphi的帮助
    The CopyFile function copies an existing file to a new file. BOOL CopyFile(    LPCTSTR lpExistingFileName, // pointer to name of an existing file 
        LPCTSTR lpNewFileName, // pointer to filename to copy to 
        BOOL bFailIfExists  // flag for operation if file exists 
       );
     ParameterslpExistingFileNamePoints to a null-terminated string that specifies the name of an existing file. lpNewFileNamePoints to a null-terminated string that specifies the name of the new file. bFailIfExistsSpecifies how this operation is to proceed if a file of the same name as that specified by 
    lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.  Return ValuesIf the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError.
      

  8.   

    最后一参数当为TRUE时为中止,FALSE为覆盖。
      

  9.   

    那你干脆在Copy时将文件重命名
      

  10.   

    刚问错了,是要COPY的文件和当前运行的文件同名,要先退出,再COPY,再运行COPY过来的新文件怎么做?
      

  11.   

    to  wanghong9631217:
    不行啊,有要求就是要覆盖后再运行。
      

  12.   

    推荐你做一引发程序,比较,决定是否copy,如需要,删除当然文件,copy,运行要求的程序。