ShFileOperation和copyfile的问题(100分)

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

lbsong

Unregistered / Unconfirmed
GUEST, unregistred user!
1.用ShFileOperation做目录树的copy时,pfrom 的值中如果有驱动器名的话,例如:<br>pfrom := pchar('D:/Data'),copy时,提示:文件系统出错(1026),而没有驱动器名时,<br>例如:pfrom := pchar('/Data'),copy时,可以正常copy,怎么回事?怎么办?<br>2.copyfile如何得到错误类型<br>
 
If the function succeeds, the return value is nonzero.<br>If the function fails, the return value is zero. To get extended error information, call <br>&lt;font size=20&gt;GetLastError. &lt;/font&gt;
 
我试过,没有错啊!!<br>c:/temp to d:/temp<br>c:/temp to //a/temp<br>//a/temp to d:/temp<br>都可以正常运行!!!
 
to hhzh426<br>&nbsp; 是操作系统的问题吗?我用的是WIn98,而Windows SDK Help中有这么一行字:<br>[Now Supported on Windows NT]<br>
 
自己不好好看一下帮助,这100分还是给我吧<br>pFrom :<br>Pointer to a buffer that specifies one or more source file names. <br>Multiple names must be null-separated. <br>The list of names must be double null-terminated.//后面要加两个空结束符#0#0<br>这是bcb的例子:<br>SHFILEOPSTRUCT cp1;<br>cp1.hwnd=Form1-&gt;Handle;<br>cp1.wFunc=FO_COPY;<br>cp1.pFrom="E://*.*/x0/x0"; &nbsp; &nbsp;//两个空结束符/x0/x0<br>cp1.pTo="C://temps///x0/x0"; &nbsp;//两个空结束符/x0/x0<br>cp1.fFlags=FOF_NOCONFIRMMKDIR;<br>cp1.fAnyOperationsAborted=true;<br>cp1.lpszProgressTitle="Copy";<br>cp1.hNameMappings=NULL;<br>SHFileOperation(&amp;cp1);<br><br>
 
正如wangxd所说的那样,不同的文件之间用一个#0隔开,用#0#0结束。<br>我是在98下执行的,下面是我的程序的一个部分。<br>var<br>&nbsp; &nbsp;OpStruc: TSHFileOpStruct;<br>&nbsp; &nbsp;i:integer;<br>&nbsp; &nbsp;filename,temppath,dealfiles,backupname:string;<br>&nbsp; &nbsp;frombuf,tobuf:array[0..65535] of char;<br>begin<br>&nbsp; &nbsp; &nbsp;.....<br>&nbsp; &nbsp; &nbsp;FillChar( frombuf, Sizeof(frombuf), 0 );<br>&nbsp; &nbsp; &nbsp;FillChar( tobuf, Sizeof(tobuf), 0 );<br>&nbsp; &nbsp; &nbsp;StrPCopy( frombuf,dealfiles);//dealfiles要复制的文件,如果是多个文件的话用;分开。<br>&nbsp; &nbsp; &nbsp;for i:=0 to length(dealfiles) do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if frombuf=';' then frombuf:=#0;<br>&nbsp; &nbsp; &nbsp;StrPCopy( tobuf, backupname);//backupname是要复制文件的目标目录<br>&nbsp; &nbsp; &nbsp;With OpStruc DO Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Wnd:= Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wFunc:= FO_COPY;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pFrom:= @frombuf[1];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pTo:=@tobuf;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fFlags:= FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted:= False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hNameMappings:= Nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpszProgressTitle:= Nil;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;ShFileOperation( OpStruc );<br>&nbsp; &nbsp; &nbsp;.....<br>end;<br>
 
可是我为什么不行?我真的很愚笨,还请两位再拉兄弟一把,下面是我的程序,请指教:<br>procedure TfmExportall.Button1Click(Sender: TObject);<br>var<br>&nbsp; &nbsp; outdir: string;<br>&nbsp; &nbsp; SHFileOpStruct: TSHFileOpStruct;<br>begin<br>&nbsp; inherited;<br>&nbsp; &nbsp; if selectdirectory('导出到','',outdir) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; with SHFileOpStruct do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Wnd := fmExportAll.Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wFunc := Fo_Copy;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pFrom := pchar('D:/Data/#0#0');//‘D:/Data/*.*#0#0’,'D:/Data','d:/data/#0'我都试了<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pTo := pchar(outDir+'/Data');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fFlags := FOF_NOCONFIRMMKDIR;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted := false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hNameMappings := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpszProgressTitle := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; ShFileOperation(SHFileOpStruct);<br>&nbsp; &nbsp; &nbsp; &nbsp; fmExportAll.Refresh;<br>&nbsp; &nbsp; end;<br>end;<br>
 
pFrom := pchar('D:/Data/#0#0'); //改为'd:/data#0#0' 或为'd:/data/*.*#0#0' <br>pTo := pchar(outDir+'/Data'); &nbsp; //改为pchar(outDir+'/Data#0#0')<br>行乐,给分吧<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
pfrom指向的是欲复制的文件列表。<br>pto指向的是目标目录。
 
感谢两位的耐心解答,在下不胜感激
 
后退
顶部