请问在delphi中拷贝整个文件夹怎么操作?急!

sunboy2002 2003-01-10 05:21:04
比如我要将光盘的g:\document整个文件夹(可以有子文件夹)复制到d:\中,请问怎么办?
...全文
369 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunboy2002 2003-01-13
  • 打赏
  • 举报
回复
谢谢楼上的各位,尤其是xiaoxiao197821(洪飞),就是我要的功能!我给你们加分了!
xiaoxiao197821 2003-01-11
  • 打赏
  • 举报
回复
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;
var
hFindFile:Cardinal;
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//记录当前目录
sCurDir:=GetCurrentDir;
ChDir(sDirName);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile<>INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then
ForceDirectories(sToDirName);
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+'\'+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)]<>'\' then
DoCopyDir(sDirName+'\'+tfile,t)
else
DoCopyDir(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+'\'+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until FindNextFile(hFindFile,FindFileData)=false;
/// FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到当前目录
ChDir(sCurDir);
result:=true;
end;
lizongqi 2003-01-10
  • 打赏
  • 举报
回复
楼上的真会,这都行,呵呵
liqianglqlq 2003-01-10
  • 打赏
  • 举报
回复
一个文件复制的例子:
var
s2,d2:string;
begin
s2:='c:\公文\file2.val';
d2:=s2;
//使用前要:table1.Database.Close;
// table1.Active:=false;//////切记

if (Length(s2)<=0)OR(Length(d2)<=0) then Exit;
try
if Not(table1.Active) then begin
sS := TFileStream.Create(s2,fmOpenRead); //fmsharedenynone
d2:='d:\公文\file2.val';
try sD := TFileStream.Create(d2, fmOpenWrite or fmCreate);
try sD.CopyFrom(sS, sS.Size);
finally sD.Free;
end;
finally sS.Free;
end;
end;
except
showmessage('文件打开错误');
end;

你看看,能不能帮你
lizongqi 2003-01-10
  • 打赏
  • 举报
回复
up
xirumin 2003-01-10
  • 打赏
  • 举报
回复
winexec( 'xcopy命令',false);
naughtyboy 2003-01-10
  • 打赏
  • 举报
回复
move()
fyje 2003-01-10
  • 打赏
  • 举报
回复
下面这段代码实现这个功能:
if findfirst('g:\document\*.*',faArchive,sr)<>0
then findclose(sr)
else
begin
repeat
Bfilename:='g:\document\'+sr.Name;
Nfilename:='d:\'+sr.Name;
movefile(pchar(BfileName),pchar(NfileName));
until FindNext(sr) <> 0;
FindClose(sr);
end;
gaga_ghost 2003-01-10
  • 打赏
  • 举报
回复
procedure TForm1.Button3Click(Sender: TO b j e c t ) ;
v a r
OpStruc: TSHFileOpStruct;
FromBuf, ToBuf: Array [0..128] of Char;
b e g i n
FillChar( FromBuf, Sizeof(FromBuf), 0 );
FillChar( ToBuf, Sizeof(ToBuf), 0 );
StrPCopy( FromBuf, Pchar(Edit1.Text) );
StrPCopy( ToBuf, Pchar(Edit2.Text) );
// 设置O p S t r u c
with OpStruc do
b e g i n
Wnd:= Handle;
wFunc:= FO_COPY;
pFrom:= @FromBuf;
p To : = @ To B u f ;
f F l a g s : = F O F _ N O C O N F I R M ATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:= False;
hNameMappings:= nil;
l p s z P r o g r e s s Title:= nil;
e n d ;
if SHFileOperation( OpStruc ) = 0 then
....

1,183

社区成员

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

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