有什么函数可以复制文件的吗?能帮我解决问题的!!100分

sos606 2003-05-17 08:25:46
很多人说用API,但具体怎么做呢?(我没用过AIP:))
例如有没有这样的函数:copyfile(fromstring\file.exe,tostring);fromstring是要复制的文件的目录,

tostring是准备要复制文件到那的目录!!
help,help!100分。
...全文
81 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
riverliu 2003-05-18
  • 打赏
  • 举报
回复
赞成楼上的方法,用
CopyFile(SourceFileName,DesFileName, False|True)
chenfeng3000 2003-05-18
  • 打赏
  • 举报
回复
CopyFile(SourceFile, ObjFile, false);
false 覆盖文件
true 同名文件,不覆盖
李_军 2003-05-18
  • 打赏
  • 举报
回复
CopyFile('.\Data\DataPro.mdb', 'D:\DataPro.mdb', False);
sos606 2003-05-18
  • 打赏
  • 举报
回复
怎么用copyfile运行可以,但根本就没复制到文件.??
u2m 2003-05-17
  • 打赏
  • 举报
回复
CopyFile('.\Data\DataPro.mdb', 'D:\DataPro.mdb', False);
智商无下限 2003-05-17
  • 打赏
  • 举报
回复
同意楼上的 直接用COPYFILE(‘你要复制的文件’,‘目标文件’,是否覆盖同名的文件);
TechnoFantasy 2003-05-17
  • 打赏
  • 举报
回复
通过调用Win 95系统外壳来完成,需要在USES子句中添加SHELLAPI单元。这种方法与Win 95下文件拷贝的方式完全一样,也会自动出现“正在拷贝...”的提示。如果目标文件已经存在,函数可以根据操作标志位自动生成多份复件。

  改变wFunc的值,则可以完成删除、更名、放到回收站等功能。笔者认为这是最好的一种方法。
  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;
Maple119 2003-05-17
  • 打赏
  • 举报
回复
方法一: CopyFile('.\Data\DataPro.mdb', 'D:\DataPro.mdb', False);
方法二:
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,如第二种写法
TechnoFantasy 2003-05-17
  • 打赏
  • 举报
回复
可以使用API函数CopyFile。如:
CopyFile('c:\autoexec.bat', 'd:\my.bat', false);
如果要拷贝多个文件或整个目录,可以使用SHFileOperation。
sdzeng 2003-05-17
  • 打赏
  • 举报
回复
FileExists(const FileName: string): Boolean;判断文件是否存在

BOOL CopyFile(

LPCTSTR lpExistingFileName, // 已经存在的文件名
LPCTSTR lpNewFileName, // 新文件名称
BOOL bFailIfExists // 如果文件存在是否报错
);

其他文件函数:
参见Delphi帮助和W32 SDK Help

delphi函数:

AssignFile procedure

Associates the name of an external file with a file variable.

ChDir procedure

Changes the current directory.

CloseFile procedure

Terminates the association between file variable and an external disk file.

CreateDir function

Creates a new directory.

DeleteFile function

Deletes a file from disk.

DirectoryExists function

Determines whether a specified directory exists.

DiskFree function

Returns the number of free bytes on a specified drive.

DiskSize function

Returns the size, in bytes, of a specified drive.

File mode constants

File mode constants are used to open and close disk files.

File open mode constants

File open mode constants are used to control the access mode to a file or stream.

FileAge function

Returns the OS timestamp of a file.

FileClose procedure

Closes a specified file.

FileCreate function

Creates a new file.

FileDateToDateTime function

Converts an OS timestamp value to TDateTime value.

FileExists function

Tests if a specified file exists.

FileGetAttr function

Returns the file attributes of FileName.

FileGetDate function

Returns an OS timestamp for a specified file.

FileIsReadOnly function

Report if file is read-only.

FileOpen function

Opens a specified file using a specified access mode.

FileRead function

Reads a specified number of bytes from a file.

FileSearch function

Searches a specified directory path for a file.

FileSeek function

Repositions read/write point.

FileSetAttr function

Sets the file attributes of a specified file.

FileSetDate function

Sets the OS time stamp for a specified file.

FileWrite function

Writes the contents of a buffer to the current position in a file.

FindClose procedure

Releases memory allocated by FindFirst.

FindFirst function

Searches for the first instance of a file name with a given set of attributes in a specified directory.

FindNext function

Returns the next entry matching the name and attributes specified in a previous call to FindFirst.

ForceDirectories function

Creates a new directory, also creating parents as needed.

GetCurrentDir function

Returns the name of the current directory.

GetDir procedure

Returns the current directory for a specified drive.

RemoveDir function

Deletes an existing empty directory.

RenameFile function

Changes a file name.

SetCurrentDir function

Sets 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

pingshx 2003-05-17
  • 打赏
  • 举报
回复
要用这个函数:ShFileOperation。要uses shlapi;
eliphe 2003-05-17
  • 打赏
  • 举报
回复
CopyFile('.\Data\DataPro.mdb', 'D:\DataPro.mdb', False);

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧