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;
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.
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.
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.
具体的可以看看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.
不行啊,有要求就是要覆盖后再运行。