如何复制某个盘的全部文件和文件夹? ( 积分: 100 )

  • 主题发起人 主题发起人 霖霖
  • 开始时间 开始时间

霖霖

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过程序实现把硬盘上的某个盘(比如C:盘)上的文件和文件夹全部复制到另一个盘中去(比如D:盘),该怎么写代码?查阅了相关的资料后知道可以用 ShFileOperation 实现,可我对这个不熟悉,请高手指点。最好给出Demo代码。<br>感谢啦~~~!!!!!!!!!
 
我想通过程序实现把硬盘上的某个盘(比如C:盘)上的文件和文件夹全部复制到另一个盘中去(比如D:盘),该怎么写代码?查阅了相关的资料后知道可以用 ShFileOperation 实现,可我对这个不熟悉,请高手指点。最好给出Demo代码。<br>感谢啦~~~!!!!!!!!!
 
遍历整个C盘,然后一个个复制过去<br><br>用FindFirst和FindNext查找,查到的排除'.'和'..'的,余下用DirectoryExist判断是目录的.用MkDir或CreateDir或CreateDirectory在目的位置建立目录,否则的就是文件,用CopyFile复制吧.<br><br>注意:<br>1.遍历C盘时不要采用递归,否则内存耗得厉害,而定义个TStringsList,用add,del先进后出的原则来保存遍历的目录的方法.<br>2.如果复制的目录和文件的属性也要一致.目录要用CreateDirectory,文件CopyFile后用<br>FileSetAttr更改.
 
帮你顶下![:D]
 
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;<br>var<br> &nbsp; hFindFile:Cardinal;<br> &nbsp; t,tfile:String;<br> &nbsp; sCurDir:String[255];<br> &nbsp; FindFileData:WIN32_FIND_DATA;<br>begin<br> &nbsp; //先保存当前目录<br> &nbsp; sCurDir:=GetCurrentDir;<br> &nbsp; ChDir(sDirName);<br> &nbsp; hFindFile:=FindFirstFile('*.*',FindFileData);<br> &nbsp; if hFindFile &lt;&gt; INVALID_HANDLE_VALUE then<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if not DirectoryExists(sToDirName) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ForceDirectories(sToDirName);<br> &nbsp; &nbsp; &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tfile:=FindFileData.cFileName;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tfile='.') or (tfile='..') then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Continue;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FindFileData.dwFileAttributes=<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_DIRECTORY then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:=sToDirName+'/'+tfile;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &nbsp;not DirectoryExists(t) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ForceDirectories(t);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sDirName[Length(sDirName)]&lt;&gt;'/' then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DoCopyDir(sDirName+'/'+tfile,t)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DoCopyDir(sDirName+tfile,sToDirName+tfile);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:=sToDirName+'/'+tFile;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyFile(PChar(tfile),PChar(t),True);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;until FindNextFile(hFindFile,FindFileData)=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;FindClose(hFindFile);<br> &nbsp; end<br> &nbsp; else<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ChDir(sCurDir);<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; end;<br> &nbsp; //回到原来的目录下<br> &nbsp; ChDir(sCurDir);<br> &nbsp; result:=true;<br>end;
 
To songjy:<br>你贴的代码怎么不能编译通过呀?<br>(1)编译时CopyFile(PChar(tfile),PChar(t),True);报错:[Error] Unit1.pas(371): Too many actual parameters。我查看Win32帮助发现的确是要三个参数的呀,但不知为何总是报错,我改为CopyFile(PChar(tfile),PChar(t));却可以通过编译。我的系统为WinXP SP2。<br>(2)编译时FindClose(hFindFile);报错:[Error] Unit1.pas(375): Types of actual and formal var parameters must be identical。暂时还不知如何解决。<br><br>不知哪位高人能解决上面的问题?
 
(2)编译时FindClose(hFindFile);报错:<br>看delphi帮助 FindClose(var F: TSearchRec);而你的hfindfile为Cardinal;
 
在这里hFindFile:=FindFirstFile('*.*',FindFileData);<br>hfindfile一定要为Cardinal类型,否则通不过。<br>在win32 SDK中定义是<br>HANDLE FindFirstFile(<br> &nbsp; &nbsp;LPCTSTR lpFileName, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // pointer to name of file to search for &nbsp;<br> &nbsp; &nbsp;LPWIN32_FIND_DATA lpFindFileData // pointer to returned information <br> &nbsp; );
 
function f_OpFolder(p_FromDir,p_ToDir: string; p_Handle: THandle; <br> &nbsp; p_Type:Integer): Integer; <br>//**************************************************** <br>//说明 <br>//文件夹操作函数 <br><br>//参数 <br>//p_FromDir 操作源文件夹 <br>//p_ToDir &nbsp; 操作目标文件夹 <br>//p_Handle &nbsp;Application.Handle <br>//p_Type &nbsp; &nbsp;操作类型 &nbsp;0: 复制 1:移动 2:删除 3:重命名 <br><br>//返回值 0:操作失败 1:操作成功 <br>//**************************************************** <br>var <br> v_SHFOS: TSHFILEOPSTRUCT; <br> v_ToDir, v_FromDir: array[0..2048] of Char; <br>begin <br> Result:=0; <br> FillChar(v_SHFOS, Sizeof(v_SHFOS), #0); <br> if not DirectoryExists(p_FromDir) then <br> &nbsp; begin <br> &nbsp; &nbsp; MessageBoxW(p_Handle,'操作文件夹不存在!','注意',MB_OK+MB_ICONINFORMATION); <br> &nbsp; &nbsp; Exit; <br> &nbsp; end; <br> FillChar(v_FromDir, Sizeof(v_FromDir), #0); <br> FillChar(v_ToDir, Sizeof(v_ToDir), #0); <br> StrPCopy(v_FromDir, p_FromDir); <br> StrPCopy(v_ToDir, p_ToDir); <br> //*************************************************************************** <br> v_SHFOS.Wnd &nbsp; := p_Handle; <br> v_SHFOS.pFrom := @v_FromDir; //源路径 <br> v_SHFOS.pTo &nbsp; := @v_ToDir; //目标路径 <br> v_SHFOS.hNameMappings := nil; &nbsp;//不使用Map文件 <br> v_SHFOS.fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_MULTIDESTFILES &nbsp;or <br> &nbsp; FOF_NOCONFIRMMKDIR or FOF_SIMPLEPROGRESS;//允许撤消,不出现确定窗口,需要创建新目录时不提示 <br> case p_Type of <br> 0:begin &nbsp;//复制 <br> &nbsp; &nbsp; v_SHFOS.lpszProgressTitle := '正在拷贝数据文件...'; //显示进度窗口的Caption <br> &nbsp; &nbsp; v_SHFOS.wFunc := FO_COPY; //执行COPY操作 <br> &nbsp; end; <br> 1:begin &nbsp;//移动 <br> &nbsp; &nbsp; v_SHFOS.lpszProgressTitle := '正在拷贝数据文件...'; //显示进度窗口的Caption <br> &nbsp; &nbsp; v_SHFOS.wFunc := FO_MOVE; //执行MOVE操作 <br> &nbsp; end; <br> 2:begin &nbsp;//删除 <br> &nbsp; &nbsp; v_SHFOS.lpszProgressTitle := '正在删除数据文件...'; //显示进度窗口的Caption <br> &nbsp; &nbsp; v_SHFOS.wFunc := FO_DELETE; //执行DELETE操作 <br> &nbsp; end; <br> 3:begin &nbsp;//重命名 <br> &nbsp; &nbsp; if ExtractFilePath(LowerCase(p_FromDir))&amp;lt;&amp;gt;ExtractFilePath(LowerCase(p_ToDir)) then <br> &nbsp; &nbsp; &nbsp; begin <br> &nbsp; &nbsp; &nbsp; &nbsp; MessageBoxW(p_Handle,'文件夹制定路径不一致!','注意',MB_OK+MB_ICONINFORMATION); <br> &nbsp; &nbsp; &nbsp; &nbsp; Exit; <br> &nbsp; &nbsp; &nbsp; end; <br> &nbsp; &nbsp; v_SHFOS.wFunc := FO_RENAME; //执行RENAME操作 <br> &nbsp; end; <br> else <br> &nbsp; Exit; <br> end; <br> //*************************************************************************** <br> if ShFileOperation(v_SHFOS)=0 then <br> &nbsp; Result:=1; <br>end;
 
To Avalon:<br>我这样调用 f_OpFolder('C:','E:/Temp', Application.Handle,0) 你给出的函数,结果出错,提示说“无法复制文件:无法读源文件或磁盘”。<br>如果复制文件夹就没问题,例如:f_OpFolder('C:/AAA','E:/Temp', Application.Handle,0) ,可以正确运行。<br><br>该如果解决?
 
?<br>??<br>???<br>????<br>?????
 
很简单的 你用winexec('cmd.exe /c xcopy c:/ 目标 /参数',sw_hide);<br>XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [/C] [/I] [/Q] [/F] [/L] [/H] [/<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [/K] [/N] [/O] [/X] [/Y] [/-Y] [<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [/EXCLUDE:file1[+file2][+file3].<br><br> &nbsp;source &nbsp; &nbsp; &nbsp; 指定要复制的文件。<br> &nbsp;destination &nbsp;指定新文件的位置和/或名称。<br> &nbsp;/A &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 只复制有存档属性集的文件,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 但不改变属性。<br> &nbsp;/M &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 只复制有存档属性集的文件,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 并关闭存档属性。<br> &nbsp;/D:m-d-y &nbsp; &nbsp; 复制在指定日期或指定日期以后改变的文件。<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果没有提供日期,只复制那些源时间<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 比目标时间新的文件。<br> &nbsp;/EXCLUDE:file1[+file2][+file3]...<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 指定含有字符串的文件列表。如果有任何<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 字符串与要被复制的文件的绝对路径<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 相符,那个文件将不会得到复制。<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 例如,指定如 /obj/ 或 .obj 的字符串会排除<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 目录 obj 下面的所有文件或带有<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .obj 扩展名的文件。<br> &nbsp;/P &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 创建每个目标文件前提示。<br> &nbsp;/S &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制目录和子目录,除了空的。<br> &nbsp;/E &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制目录和子目录,包括空的。<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 与 /S /E 相同。可以用来修改 /T。<br> &nbsp;/V &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 验证每个新文件。<br> &nbsp;/W &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 提示您在复制前按键。<br> &nbsp;/C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 即使有错误,也继续复制。<br> &nbsp;/I &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 如果目标不存在,又在复制一个以上的文件,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 则假定目标一定是一个目录。<br> &nbsp;/Q &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制时不显示文件名。<br> &nbsp;/F &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制时显示完整的源和目标文件名。<br> &nbsp;/L &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 显示要复制的文件。<br> &nbsp;/H &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 也复制隐藏和系统文件。<br> &nbsp;/R &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 改写只读文件。<br> &nbsp;/T &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 创建目录结构,但不复制文件。不<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 包括空目录或子目录。/T /E 包括<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 空目录和子目录。<br> &nbsp;/U &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 只复制已经存在于目标中的文件。<br> &nbsp;/K &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制属性。一般的 Xcopy 会重设只读属性。<br> &nbsp;/N &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 用生成的短名复制。<br> &nbsp;/O &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制文件所有权和 ACL 信息。<br> &nbsp;/X &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 复制文件审核设置(隐含 /O)。<br> &nbsp;/Y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 禁止提示以确认改写一个<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 现存目标文件。<br> &nbsp;/-Y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;导致提示以确认改写一个<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 现存目标文件。<br> &nbsp;/Z &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 用重新启动模式复制网络文件。<br><br>命令选项 /Y 可以预先在 COPYCMD 环境变量中设置。<br>这可能被命令行上的 /-Y 改写。
 
用findnext和findfirst?我晕,这是谁想的主意哦,我同意楼上的兄弟,只是可能用ShellExecute来启动好些。
 
我以前用的就是WinExec(),就是想换一种方法。<br>这种方法有个弊端就是如果系统中没有xcopy.exe就不行了。
 
系统安装时候自动都有的,而且受文件保护系统保护!当然你可以自己携带它,用的时候从资源里面释放出来!
 
怎么可能这么简单呢?pagefile.sys这类文件你在ring3根本无法打开它的句柄,也就根本无法复制,ghost不是这么容易做的,我以前做的时候直接打开//device/harddisk/dr0设备,然后根据ntfs或者fat格式,自己一个接一个的分析扇区,这样的备份软件现在在国外可以卖大价钱,怎么是你们认为的这么简单呢!
 
unit Unit2;<br><br><br>interface<br>uses<br> &nbsp; Windows,Messages, SysUtils, Variants;<br>implementation<br>function DoCopyDir(sDirName:String;sToDirName:String):Boolean;<br>var<br> &nbsp; hFindFile:Cardinal;<br> &nbsp; t,tfile:String;<br> &nbsp; sCurDir:String[255];<br> &nbsp; FindFileData:WIN32_FIND_DATA;<br>begin<br> &nbsp; sCurDir:=GetCurrentDir;<br> &nbsp; ChDir(sDirName);<br> &nbsp; hFindFile:=FindFirstFile('*.*',FindFileData);<br> &nbsp; if hFindFile &lt;&gt; INVALID_HANDLE_VALUE then<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if not DirectoryExists(sToDirName) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ForceDirectories(sToDirName);<br> &nbsp; &nbsp; &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tfile:=FindFileData.cFileName;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (tfile='.') or (tfile='..') then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Continue;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FindFileData.dwFileAttributes=<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_DIRECTORY then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:=sToDirName+'/'+tfile;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if &nbsp;not DirectoryExists(t) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ForceDirectories(t);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if sDirName[Length(sDirName)]&lt;&gt;'/' then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DoCopyDir(sDirName+'/'+tfile,t)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DoCopyDir(sDirName+tfile,sToDirName+tfile);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:=sToDirName+'/'+tFile;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CopyFile(PChar(tfile),PChar(t),True);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;until FindNextFile(hFindFile,FindFileData)=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;FindClose(hFindFile);<br> &nbsp; end<br> &nbsp; else<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ChDir(sCurDir);<br> &nbsp; &nbsp; &nbsp; &nbsp;result:=false;<br> &nbsp; &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; end;<br> &nbsp; //回到原来的目录下<br> &nbsp; ChDir(sCurDir);<br> &nbsp; result:=true;<br>end;<br><br>end.<br><br><br><br>这段代码肯定是可以通过的,原因在于uses 语句
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;FromBuf,ToBuf:array[0..128] of char;<br> &nbsp;OpStruc: TSHFileOpStruct;<br>begin<br>FillChar(FromBuf,SizeOf(FromBuf),0);<br> &nbsp; &nbsp; &nbsp; FillChar(ToBuf,SizeOf(ToBuf),0);<br> &nbsp; &nbsp; &nbsp; StrPCopy(FromBuf,PChar('c:/'));<br> &nbsp; &nbsp; &nbsp; StrPCopy(ToBuf,PChar(extractfilepath(application.ExeName)));<br> &nbsp; &nbsp; &nbsp; with OpStruc do<br> &nbsp; &nbsp; &nbsp; 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;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pTo := @ToBuf;<br> &nbsp; &nbsp; &nbsp; &nbsp;fFlags:=FOF_NOCONFIRMATION;//FOF_ALLOWUNDO;FOF_NOCONFIRMATION;FOF_RENAMEONCOLLISION ; fof_filesonly;<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>end;
 
To songjy:<br> &nbsp;你编译能不能通过呀?我编译时总是FindClose(hFindFile)这里过不去,提示[Error] Unit1.pas(138): Types of actual and formal var parameters must be identical<br><br>To guoqun:<br> &nbsp; 编译出错,提示说“无法复制文件:无法读源文件或磁盘”。
 
To songjy:<br> &nbsp;你编译能不能通过呀?我编译时总是FindClose(hFindFile)这里过不去,提示[Error] Unit1.pas(138): Types of actual and formal var parameters must be identical<br><br>To guoqun:<br> &nbsp; 编译出错,提示说“无法复制文件:无法读源文件或磁盘”。
 
后退
顶部