如何进行文件拷贝和重命名,DELPHI中有没自己的函数,还是要用API(50分)

  • 主题发起人 主题发起人 chrisn
  • 开始时间 开始时间
C

chrisn

Unregistered / Unconfirmed
GUEST, unregistred user!
请指教,给出函数原形和参数说明
 
copyfile
renamefile
DELPHI帮助里都有的,查一下
 
文件拷贝
procedure CopyFile(const FileName, DestName: TFileName);
var
CopyBuffer: Pointer;
TimeStamp, BytesCopied: Longint;
Source, Dest: Integer;
Destination: TFileName;
const
ChunkSize: Longint = 8192;
begin
Destination := ExpandFileName(DestName);
if HasAttr(Destination, faDirectory) then
Destination := Destination + '/' + ExtractFileName(FileName);
TimeStamp := FileAge(FileName);
GetMem(CopyBuffer, ChunkSize);
try
Source := FileOpen(FileName, fmShareDenyWrite);
if Source < 0 then
raise EFOpenError.Create(FmtLoadStr(SFOpenError, [FileName]));
try
Dest := FileCreate(Destination);
if Dest < 0 then
raise EFCreateError.Create(FmtLoadStr(SFCreateError, [Destination]));
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize);
if BytesCopied > 0 then
FileWrite(Dest, CopyBuffer^, BytesCopied);
until BytesCopied < ChunkSize;
finally
FileClose(Dest);
end;
finally
FileClose(Source);
end;
finally
FreeMem(CopyBuffer, ChunkSize);
end;
end;
 
function CopyFileTo(const Source: string; const Destination: string): Boolean;
function RenameFile(const OldName, NewName: string): Boolean;
 
重命名函数RenameFile,
如: RenameFile(’c:wang emp’, ’c:wang mp’);
 
对文件的扩展名能不能一并修改
 
uses ShellAPI;

SHFileOperation
 
有API,你也可以自己做。
要是改名的的话至少有N种方法。
复制的话你可以用STREAM,或者直接用BLOCKREAD,BLOCKWRITE什么的。
 
我再罗嗦一句,改名的话不论是用api的RenameFile,
还是DELPHI的rename都可以对文件夹进行改名操作,
更好的是,它们都可以实现文件/文件夹的移动,
如果是本分区内移动,基本上是零时间。
 
deletefile( filePath );
renamefile( NewFilePath , OldFileName);
 
如何在打开的对话框中选中的文件拷贝到剪贴板中呢?
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
926
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部