很多人说用API,但具体怎么做呢?(我没用过AIP:))
例如有没有这样的函数:copyfile(fromstring\file.exe,tostring);fromstring是要复制的文件的目录,tostring是准备要复制文件到那的目录!!
help,help!100分。
例如有没有这样的函数:copyfile(fromstring\file.exe,tostring);fromstring是要复制的文件的目录,tostring是准备要复制文件到那的目录!!
help,help!100分。
LPCTSTR lpNewFileName, // 新文件名称
BOOL bFailIfExists // 如果文件存在是否报错
);
其他文件函数:
参见Delphi帮助和W32 SDK Helpdelphi函数:AssignFile procedureAssociates the name of an external file with a file variable.ChDir procedureChanges the current directory.CloseFile procedureTerminates the association between file variable and an external disk file.CreateDir functionCreates a new directory.DeleteFile functionDeletes a file from disk.DirectoryExists functionDetermines whether a specified directory exists.DiskFree functionReturns the number of free bytes on a specified drive.DiskSize functionReturns the size, in bytes, of a specified drive.File mode constantsFile mode constants are used to open and close disk files.File open mode constantsFile open mode constants are used to control the access mode to a file or stream.FileAge functionReturns the OS timestamp of a file.FileClose procedureCloses a specified file.FileCreate functionCreates a new file.FileDateToDateTime functionConverts an OS timestamp value to TDateTime value.FileExists functionTests if a specified file exists.FileGetAttr functionReturns the file attributes of FileName.FileGetDate functionReturns an OS timestamp for a specified file.FileIsReadOnly functionReport if file is read-only.FileOpen functionOpens a specified file using a specified access mode.FileRead functionReads a specified number of bytes from a file.FileSearch functionSearches a specified directory path for a file.FileSeek functionRepositions read/write point.FileSetAttr functionSets the file attributes of a specified file.FileSetDate functionSets the OS time stamp for a specified file.FileWrite functionWrites the contents of a buffer to the current position in a file.FindClose procedureReleases memory allocated by FindFirst.FindFirst functionSearches for the first instance of a file name with a given set of attributes in a specified directory.FindNext functionReturns the next entry matching the name and attributes specified in a previous call to FindFirst.ForceDirectories functionCreates a new directory, also creating parents as needed.GetCurrentDir functionReturns the name of the current directory.GetDir procedureReturns the current directory for a specified drive.RemoveDir functionDeletes an existing empty directory.RenameFile functionChanges a file name.SetCurrentDir functionSets the current directory.api函数
AreFileApisANSI
CancelIO
CopyFile
CopyFileEx
CopyProgressRoutine
CreateDirectory
CreateDirectoryEx
CreateFile
CreateIoCompletionPort
DefineDosDevice
DeleteFile
FileIOCompletionRoutine
FindClose
FindCloseChangeNotification
FindFirstChangeNotification
FindFirstFile
FindFirstFileEx
FindNextChangeNotification
FindNextFile
FlushFileBuffers
GetBinaryType
GetCompressedFileSize
GetCurrentDirectory
GetDiskFreeSpace
GetDiskFreeSpaceEx
GetDriveType
GetFileAttributes
GetFileAttributesEx
GetFileInformationByHandle
GetFileSize
GetFileType
GetFullPathName
GetLogicalDrives
GetLogicalDriveStrings
GetQueuedCompletionStatus
GetShortPathName
GetTempFileName
GetTempPath
GetVolumeInformation
LockFile
LockFileEx
MoveFile
MoveFileEx
PostQueuedCompletionStatus
QueryDosDevice
ReadDirectoryChangesW
ReadFile
ReadFileEx
RemoveDirectory
SearchPath
SetCurrentDirectory
SetEndOfFile
SetFileApisToANSI
SetFileApisToOEM
SetFileAttributes
SetFilePointer
SetVolumeLabel
UnlockFile
UnlockFileEx
WriteFile
WriteFileEx
CopyFile('c:\autoexec.bat', 'd:\my.bat', false);
如果要拷贝多个文件或整个目录,可以使用SHFileOperation。
方法二:
Var
SourceFile, ObjectFile: TFileName;
Begin
SourceFile:= '.\Data\DataPro.mdb';
ObjectFile:= 'D:\DataPro.mdb';
IF CopyFile(pChar(SourceFile), pChar(OjbectFile), False) Then ;;
End;注:一、第三个参数,False 是指当文件存在时覆盖, True 当文件存在时返回假.
二、源文件与目标文件参数可以是常量字符串,也可以是变量字符串,变量字符串要加pChar,如第二种写法
procedure TForm1.Button5Click(Sender: TObject);
var
F:TShFileOpStruct;
begin
F.wnd:=Handle;
F.wFunc:=FO_COPY; {操作方式}
F.pFrom:=′C:\DEMO.DAT′;
F.pTo:=′F:\TEST.DAT′;
F.fFlags:=FOF_ALLOWUNDO OR FOF_RENAMEONCOLLISION; {操作选项}
if ShFileOperation(F)<>0 then
ShowMessage(′文件拷贝失败!′);
end;
false 覆盖文件
true 同名文件,不覆盖
CopyFile(SourceFileName,DesFileName, False|True)