RemoveFile(100分)

  • 主题发起人 主题发起人 visual_cjiajia
  • 开始时间 开始时间
V

visual_cjiajia

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
1)我在DELPHI中找不到RemoveFile这个API的位置,<br>应该怎么办?<br>2)另外:<br>我用CreateDirectory创建文件夹;系统一直报错,帮我看看我错在哪里?<br>var<br>&nbsp;d:string;<br>&nbsp;ret:BOOL;<br>&nbsp;lpSecurityAttributes :PSecurityAttributes;<br>begin<br>d:=inputbox('输入新文件夹名:','input new dir name:','newfolder');<br>if d&lt;&gt;'' then begin//1<br>&nbsp; try<br>&nbsp; d:= chkpathxie(soucanjia1)+d;<br>&nbsp; lpSecurityAttributes.nLength :=length(d);<br>&nbsp; lpSecurityAttributes.lpSecurityDescriptor:=nil;<br>&nbsp; lpSecurityAttributes.bInheritHandle :=true;<br>&nbsp; ret:=CreateDirectory (pchar(d), lpSecurityAttributes);<br>&nbsp; if ret then<br>&nbsp; &nbsp; dir1.Directory :=d;<br>&nbsp; dir1.Refresh ;<br>&nbsp; except<br>&nbsp; &nbsp;on EAccessViolation do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>&nbsp; end;//1<br>end;<br>3)为什么我用了RemoveDirectory却不能将一个目录删除?<br>if MessageBox(application.Handle ,pchar('确实要删除?'),<br>&nbsp; &nbsp;pchar('提示'),MB_YESNOCANCEL	+MB_ICONERROR)=IDYES	then<br>RemoveDirectory(pchar(dir1.Directory ));
[:(][:(][:(]
 
1) 是不是ShellApi,看一下Delphi帮助,里面有所处的单元<br>2) lpSecurityAttributes :PSecurityAttributes; 这好象是一个指针,开辟空间没?<br>3) 不能删除目录,可能是因为目录正在使用,或者目录非空(具体看帮助)
 
1。<br>DeleteFile('c:/a.txt')<br><br>2。<br>uses FileCtrl;<br><br>ForceDirectories('c:/sfd/');<br><br>3。<br>uses ShellApi;<br><br>procedure TForm1.Button1Click(Sender: TObject); <br>var <br>&nbsp; &nbsp; myrec:TSHFILEOPSTRUCT ; <br>begin <br>&nbsp; &nbsp; With myrec DO Begin <br>&nbsp; &nbsp; &nbsp; &nbsp; Wnd:= Handle; <br>&nbsp; &nbsp; &nbsp; &nbsp; wFunc:= FO_DELETE; <br>&nbsp; &nbsp; &nbsp; &nbsp; pFrom:= 'c:/tmp/*.*'; <br>&nbsp; &nbsp; &nbsp; &nbsp; pTo:=''; <br>&nbsp; &nbsp; &nbsp; &nbsp; fFlags:= FOF_NOCONFIRMATION &nbsp;or FOF_FILESONLY; <br>&nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted:= False; <br>&nbsp; &nbsp; &nbsp; &nbsp; hNameMappings:= Nil; <br>&nbsp; &nbsp; &nbsp; &nbsp; lpszProgressTitle:= Nil; <br>&nbsp; &nbsp; end; <br>&nbsp; &nbsp; SHFileOperation(myrec); <br>end;<br><br>2. <br>
 
&nbsp;建立文件夹,你可以用MKDIR();<br>1:你首先进入你要建立的文件夹的父文件夹:CHDIR();//例如进入到执行文件下面<br>&nbsp; ChDir(extractFilePath(application.exname);<br>2:建立文件夹:<br>&nbsp; MkDir(edit1.text) &nbsp; &nbsp;//功能是在可执行文件下建一个以edit1.text字符串名的文件夹<br>3:RemoveFile: 你不需要在users中调用任何东西,参数为绝对路径,当然就包括文件名拉,后坠名也要<br>&nbsp; RemoveFile(pchar(edit1.text),pchar(edit2.text));<br>&nbsp; &nbsp; edit1.text:='c:/aa.txt';<br>&nbsp; &nbsp; edit2.text:='d:/aa.txt'; &nbsp; &nbsp; &nbsp;//首先的条件是文件必须存在。<br>我一般不用removefile,,我用的是copyfile, 如果复制成功,我就删除源文件<br>&nbsp; &nbsp; copyfile(pchar(edit1.text),pchar(edit2.text),false/true); &nbsp;//false或者true 是参数,你可以选。<br>&nbsp; 复制成功以后,进入源文件的目录: <br>&nbsp; &nbsp; if fileexists(filename) <br>&nbsp; &nbsp; &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deletefile(FILENAME);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('哈哈,,拜拜,朋友');<br>&nbsp; &nbsp; &nbsp; &nbsp;end;
 
没有这个 API :RemoveFile
 
建文件夹可以用Createdir
 
哦。。。。我搞错了。。<br>是movefile(pchar(源文件),pchar(目的文件));<br>包含绝对路径
 
不过我还是认为<br>网络蚂蚁的在IE右键的“download by netants"的click事件<br>很难做因为他需要用VB脚本调用动态连接库如:<br>&lt;script language="VBScript"&gt;<br><br> On Error Resume Next<br> set NetAntsApi = CreateObject( "NetAnts.API" )<br> if err&lt;&gt;0 then<br> Alert("NetAnts not properly installed on this PC!")<br> else<br> set links = external.menuArguments.document.links<br> ReDim params(links.length*2)<br> params(0)=external.menuArguments.document.Url<br> for i = 0 to links.length-1<br> params(i*2+1)=links(i).href<br> params(i*2+2)=links(i).innerText <br> next <br> NetAntsApi.AddUrlList params<br>&nbsp; &nbsp; &nbsp; &nbsp; end if<br>&lt;/script&gt;<br>我该去哪里查找这种技术资料,望赐教!<br>
 
后退
顶部