讨论一下在delphi中多个文件从一个目录复制到另一个目录什么方法最快,(请说明如何实现) ( 积分: 100 )

  • 主题发起人 主题发起人 lovecity
  • 开始时间 开始时间
L

lovecity

Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI下调用DOS命令中的XCOPY
 
uses ShellApi;

function CopyDir(SouDir, DesDir: string): Boolean;
var
fo: TSHFILEOPSTRUCT;
begin
Result := False;
if not DirectoryExists(SouDir) then Exit;
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_MOVE;
pFrom := PChar(SouDir + #0);
pTo := PChar(DesDir + #0);
fFlags := FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR or FOF_SILENT;
end;
if SHFileOperation(fo) = 0 then
Result := True;
end;
 
大家积极啊,,看看这个话题热不热啊
 
顶起啊,,,怎么高手都没有来呢
 
COPYFILE()函数!
下面是DELPHI的帮助!

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
);
Parameters

lpExistingFileName

Points to a null-terminated string that specifies the name of an existing file.

lpNewFileName

Points to a null-terminated string that specifies the name of the new file.

bFailIfExists

Specifies 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 Value

If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error
information, call GetLastError.
 
再来一个 我自己的收藏!

函 数 名 : 文件或目录拷贝处理
功 能 : 可以连续拷贝多个文件或目录,如果目标目录不存在会自动建立一个
调用格式 : MyFunc.CopyFiles(Source:TStrings;DestDir: string);
参数说明 : Source -------------- 来源文件或目录列表
DestDir -------------- 目标目录名称
返 回 值 : 布尔型
示 例 : if Opendialog1.Execute then
begin
CopyFiles(OpenDialog1.Files,'c:/Test');
end;
此例将对话框选定的文件至"c:/Test"目录下;
}
function TMyFunc.CopyFiles(Source:TStrings;DestDir: string): boolean;
var
I:integer;
fo:TSHFILEOPSTRUCT;
Shandle:string;
begin
for I:=0 to Source.Count-1 do
begin
Shandle:=Shandle+Source+#0;
end;
Shandle:=Shandle+#0;
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := @Shandle[1];
pTo :=pchar(DestDir);
// fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR;
fFlags :=FOF_ALLOWUNDO;
end;
Result := (SHFileOperation(fo) = 0);
end;
 
FO_MOVE是剪切 FO_COPY是复制
 
觉得那个FO_COPY就行
 
后退
顶部