请教高手:怎样将一个目录下的所有目录和文件拷贝到另一个目录下?(50分)

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

cygnet_ljt

Unregistered / Unconfirmed
GUEST, unregistred user!
[blue]怎样将一个目录下的所有目录和文件拷贝到另一个目录下?[/blue]
 
Procedure cpFiles(Dir, TargetDir)<br>begin<br>&nbsp; for ..<br>&nbsp; begin<br>&nbsp; &nbsp; SubDir := API查找子目录<br>&nbsp; &nbsp; if 找不到 then break;<br>&nbsp; &nbsp; SubTargetDir := ..... <br>&nbsp; &nbsp; cpFiles(SubDir,SubTartetDir);<br>&nbsp; end;<br><br>&nbsp; API 复制本目录文件<br>&nbsp;<br>&nbsp; <br>end;<br><br>// 具体API msdn上面都有<br>// 我记不住了
 
使用一个API函数搞定:<br>function CopyDirectory(const Source, Dest: string): boolean;<br>var<br>&nbsp; fo: TSHFILEOPSTRUCT;<br>begin<br>&nbsp; FillChar(fo, SizeOf(fo), 0);<br>&nbsp; with fo do<br>&nbsp; begin<br>&nbsp; &nbsp; Wnd := 0;<br>&nbsp; &nbsp; wFunc := FO_COPY;<br>&nbsp; &nbsp; pFrom := PChar(source+#0);<br>&nbsp; &nbsp; pTo := PChar(Dest+#0);<br>&nbsp; &nbsp; fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR &nbsp; &nbsp;;<br>&nbsp; end;<br>&nbsp; Result := (SHFileOperation(fo) = 0);<br>end;<br>
 
多人接受答案了。
 
后退
顶部