怎样拷贝一个文件夹(其下所有),有这样的function??(50分)

  • 主题发起人 主题发起人 wordboy
  • 开始时间 开始时间
shell api 里有个函数<br><br>shfileoperation()
 
递归所有目录,一个个COPY。
 
Windows API:SHFileOperation<br>&nbsp; &nbsp;Performs a copy, move, rename, or delete operation on a file system object.<br>&nbsp;<br>WINSHELLAPI int WINAPI SHFileOperation(LPSHFILEOPSTRUCT lpFileOp);<br>&nbsp;<br>Parameters<br>&nbsp; lpFileOp<br>&nbsp; &nbsp; Pointer to an SHFILEOPSTRUCT structure that contains information<br>&nbsp; &nbsp; the function needs to carry out the operation.<br>Return Values<br>&nbsp; Returns zero if successful or nonzero if an error occurs.
 
Function Copydirectory(Source:string;pDirectory:string;pFilter:string):boolean;<br>//目录拷贝source :源目录 &nbsp;directory:目标目录 &nbsp;pFilter:文件类型筛选'/*.*'或'/*.???'<br>var<br>&nbsp; OpStruc: TSHFileOpStruct;<br>&nbsp; frombuf, tobuf: Array [0..128] of Char;<br>Begin<br>&nbsp; FillChar( frombuf, Sizeof(frombuf), 0 );<br>&nbsp; FillChar( tobuf, Sizeof(tobuf), 0 );<br>&nbsp; StrPCopy(frombuf, Source+pFilter);<br>&nbsp; StrPCopy( tobuf, pdirectory);<br>&nbsp; if not directoryexists(pdirectory) then<br>&nbsp; &nbsp; &nbsp; &nbsp; if not createdir(pdirectory) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('不能创建目录'+pdirectory+chr(13)+chr(10)+'或无该目录权限');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; With OpStruc DO Begin<br>&nbsp; &nbsp; Wnd:= 0;<br>&nbsp; &nbsp; wFunc:= FO_Copy;<br>&nbsp; &nbsp; pFrom:= @frombuf;<br>&nbsp; &nbsp; pTo:=@tobuf;<br>&nbsp; &nbsp; fFlags:= FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION or fof_filesonly;<br>&nbsp; &nbsp; fAnyOperationsAborted:= false;<br>&nbsp; &nbsp; hNameMappings:= Nil;<br>&nbsp; &nbsp; lpszProgressTitle:= Nil;<br>&nbsp; end;<br>&nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; ShFileOperation(OpStruc );<br>&nbsp; &nbsp; &nbsp; &nbsp; CopyDirectory:=true;<br>&nbsp; except<br>&nbsp; &nbsp; &nbsp; &nbsp;CopyDirectory:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; end;<br><br><br>end;<br><br>自己再测试一下,ok?<br><br>
 
SHFileOperation,带拷贝对话框的。
 
来晚喽!:(
 
多人接受答案了。
 
后退
顶部