如何一次拷贝多个文件(50分)

  • 主题发起人 主题发起人 陈礼泉
  • 开始时间 开始时间

陈礼泉

Unregistered / Unconfirmed
GUEST, unregistred user!
请问:如何一次拷贝多个文件。(在同一个目录下)
 
uses ShellAPI;<br><br>SHFileOperation
 
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><br>&nbsp; Begin<br>&nbsp; FillChar( frombuf, Sizeof(frombuf), 0 );<br>&nbsp; &nbsp;FillChar( tobuf, Sizeof(tobuf), 0 );<br>&nbsp; StrPCopy(frombuf, Source+pFilter);<br>&nbsp; &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; &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; &nbsp; &nbsp; end;<br>&nbsp; With OpStruc DO<br>&nbsp; &nbsp;Begin &nbsp; &nbsp;Wnd:= 0;<br>&nbsp; &nbsp; wFunc:= FO_Copy;<br>&nbsp; &nbsp; &nbsp;pFrom:= @frombuf;<br>&nbsp; &nbsp; &nbsp; pTo:=@tobuf;<br>&nbsp; &nbsp; fFlags:= FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION or FOF_SILENT ;<br>&nbsp; &nbsp; //or fof_filesonly<br>&nbsp; &nbsp; fAnyOperationsAborted:= false;<br>&nbsp; &nbsp; &nbsp;hNameMappings:= Nil;<br>&nbsp; &nbsp; lpszProgressTitle:= Nil;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp;ShFileOperation(OpStruc );<br>&nbsp; &nbsp; &nbsp; &nbsp; CopyDirectory:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;except<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CopyDirectory:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; end;
 
用api函数<br>uses ShellAPI;<br>SHFileOperation<br>具体的请看delphi帮助,<br>但我要向你说,在对多个文件进行操作的时候,<br>文件名要用#0分开,最后一个文件用#0#0结束。<br>呵呵,请给我分。谢谢。
 
SHFileOperation<br>
 
多人接受答案了。
 
后退
顶部