SHFileOperation删除文件的问题(10分)

N

no1

Unregistered / Unconfirmed
GUEST, unregistred user!
我的程序也编译在e:/share目录下,用下面的事件在删除e:/share/rep目录时出错<br>提示为:无法删除文件:文件系统错误(1026)<br>procedure TForm1.Button1Click(Sender: TObject);<br>var T:TSHfileOpStruct;<br>&nbsp; &nbsp;s:string;<br>begin<br>&nbsp; s:='e:/share/rep';<br>&nbsp; if directoryexists(pchar(s)) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; with T do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Wnd := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wFunc := FO_DELETE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pFrom := pchar(s);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pTo := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fFlags :=FOF_NOCONFIRMATION;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFileOperation(T);<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br>
 
这个文件夹下有文件在运行状态,
 
你是不是同时运行了DELPHI,DELPHI会自动保护自己当前编译的一些文件<br>还有,用这个函数无法删除自己
 
我知道你错误的原因了!!!!<br>
 
Getmem(DirName,Buffersize);<br>&nbsp;FillChar(dirname^,buffersize,0);<br>&nbsp;StrCopy(DirName,pchar(ADirName));<br><br>pFrom := DirName;<br><br>这样才行
 
这样吧:<br>var<br>&nbsp; s:string;<br>&nbsp; s:='e:/share/rep';<br>&nbsp; pFrom :=pchar(s)#0;<br>OK!
 
to 张:我是同时运行了DELPHI,但是Delphi当前编译的文件中并没有包含我要删除的文件啊<br>我要删除的文件夹和程序是独立的,一点关系也没有,我只是用我的程序去删除这个指定的目录<br><br>
 
无忌兄后面说的不错。<br>SHFileOperation的操作中如下两个参数<br> pFrom、pTo都应该是以#0结束的字串,由于此函数可对多文件进行操作,<br>这两个参数最好是以双#0结束。看看帮助文件,会有帮助的。以前我用它的<br>时候,更常见的是在win98上时好时坏,在win2000上几乎都不行。
 
接受答案
 
顶部