SHFileOperation使用的问题(50分)

  • 主题发起人 主题发起人 dinglinxiang
  • 开始时间 开始时间
D

dinglinxiang

Unregistered / Unconfirmed
GUEST, unregistred user!
var<br> &nbsp;FOS: TSHFileOpStruct;<br>begin<br> &nbsp; FillChar(FOS, SizeOf(FOS), 0); {记录清零}<br> &nbsp; with FOS do<br> &nbsp; begin<br> &nbsp; &nbsp; &nbsp; wFunc := FO_DELETE;<br> &nbsp; &nbsp; &nbsp; pFrom := PChar('D:/k.txt'); //这个文件是我特意建来测试此 api 的<br> &nbsp; &nbsp; &nbsp; fFlags := FOF_NOCONFIRMATION+FOF_MULTIDESTFILES;//+FOF_NOERRORUI;<br> &nbsp; end;<br> &nbsp; Result := (SHFileOperation(FOS) = 0);//这里报错 &nbsp;'无法读源文件或磁盘'<br><br>网上流传的一段删cookies的代码其中就有这么一段,我测试过 ,也出这个问题, 很郁闷,文件明明是存在的,, 高手帮忙看看
 
没人知道吗,,,,[:(]
 
var<br>FileDir1 :string;<br>FileStruct1:TSHFileOpStruct;<br>begin<br>FileDir1 := 'D:/Program Files/Crack Tools/调试工具/flyODBG/UDD/*.*'; &nbsp;//若是删除所有文件,则是路径 + /*.*<br>FileStruct1.Wnd :=0;<br>FileStruct1.wFunc :=FO_delete;<br>FileStruct1.pFrom:=Pchar(FileDir1+#0);<br>FileStruct1.fFlags:=FOF_NOCONFIRMATION;<br>FileStruct1.pTo :='';<br>if SHFileOperation(FileStruct1)=0 then<br>ShowMessage('粉碎完毕!');<br>end;
 
function TData1.DeleteDirectory(const Source:String): boolean;<br>//删除某个目录<br>var<br> fo: TSHFILEOPSTRUCT;<br>begin<br> FillChar(fo, SizeOf(fo), 0);<br> with fo do<br> begin<br> &nbsp; Wnd := 0;<br> &nbsp; wFunc := FO_DELETE;<br> &nbsp; pFrom := PChar(source+#0);<br> &nbsp; pTo := PChar(source+#0);<br> &nbsp; fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR &nbsp; &nbsp;;<br> end;<br> Result := (SHFileOperation(fo) = 0);<br>end;
 
// &nbsp;FO_MOVE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $0001;<br>// &nbsp;FO_COPY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $0002;<br>// &nbsp;FO_DELETE &nbsp; &nbsp; &nbsp; &nbsp; = $0003;<br>// &nbsp;FO_RENAME &nbsp; &nbsp; &nbsp; &nbsp; = $0004;<br><br>function FileOp(const SourceFile, TargetFile: string; wFunc: integer; Flags: integer &nbsp;= 0): boolean;<br>var sfosFile: TSHFileOpStruct; i: integer;<br>begin<br> &nbsp;if wFunc = FO__DELETE then<br> &nbsp; &nbsp;if not FileExists(SourceFile) then exit;<br> &nbsp;sfosFile.wFunc := wFunc;<br> &nbsp;with sfosFile do<br> &nbsp;begin<br> &nbsp; &nbsp;Wnd := Application.Handle;<br> &nbsp; &nbsp;pFrom := pChar(SourceFile + #0);<br> &nbsp; &nbsp;pTo := pChar(TargetFile);<br> &nbsp; &nbsp;if wFunc &nbsp;= FO_DELETE then<br> &nbsp; &nbsp; &nbsp;pTo := #0#0;<br> &nbsp; &nbsp;fFlags := flags;<br> &nbsp; &nbsp;fAnyOperationsAborted := true;<br> &nbsp;end;<br> &nbsp;i := SHFileOperation(sfosFile);<br> &nbsp;result := &nbsp;i = 0;<br>end;
 
把“FillChar(FOS, SizeOf(FOS), 0);”屏蔽<br>把“pFrom := PChar('D:/k.txt');”改为<br>“pFrom := PChar('D:/k.txt'+#0#0);”<br>即可了。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
896
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
后退
顶部