今天放假,我跑到公司提出个本来解决了现在又出现的问题---删除目录(100分)

  • 主题发起人 主题发起人 千中元
  • 开始时间 开始时间

千中元

Unregistered / Unconfirmed
GUEST, unregistred user!
if videosup_rb.Checked then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;edit3.Text:=extractfilepath(paramstr(0))+'videoes'; &nbsp;<br>&nbsp; &nbsp; //跟踪edit3.text的值得:c:/MY DOCUMENTS/FTP/videoes<br>&nbsp; &nbsp; &nbsp;winexec(Pchar('deltree -y '+edit3.Text),sw_hide);<br>&nbsp;请您在自己的机器上试验成功的话再答
 
验证去,分先留着
 
据我所知,deltree的用法是这样的:<br>deltree/y pathname &nbsp; (注意:deltree和/y之间不能有空格!)<br>我现在用的是NT不支持这个命令,没法验证,还请大家指正!
 
Deltree 的用法如下:<br>Deletes a directory and all the subdirectories and files in it.<br><br>To delete one or more files and directories:<br>DELTREE [/Y] [drive:]path [[drive:]path[...]]<br><br>&nbsp; /Y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Suppresses prompting to confirm you want to delete<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the subdirectory.<br>&nbsp; [drive:]path &nbsp; &nbsp;Specifies the name of the directory you want to delete.<br><br>Note: Use DELTREE cautiously. Every file and subdirectory within the<br>specified directory will be deleted.<br>你的用法应该是:<br>winexec(Pchar('deltree&lt;font color=red&gt;/y&lt;/font&gt; '+edit3.Text),sw_hide);
 
不用我的 RemoveDir?<br>Deltree NT下有这个命令吗?
 
这样子在NT下就用不了啦.老千你还是写个函数吧.<br>这样子也可以让程序长一点,呵呵.
 
&gt;&gt;'deltree -y '+edit3.Text<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;加上空格
 
xixi, 是长文件名在作怪.<br><br>命令行方式使用长文件名, 尤其是带空格的长文件名时, 要用双引号"path name"<br>括起来的. 否则会将空格认为是参数分割符.<br>
 
不行啊,还是删除不了<br>BTW:各位试过了没有???kang也不知道哪去了。。<br><br>
 
Iknow说的好象有道理,可惜我是从win98开始学电脑的,您的话听不懂啊。<br>着急往下写。。。。。。
 
IKnow说得对,<br>WinExec(PChar('deltree -y "' + Edit3.Text + '"'), SW_HIDE);<br>试验通过。<br>-y与/y都可以。<br>
 
//faint,由没有搞错,删除个目录还要调用deltree?<br>用SHFileOperation(lpFileOp)这个API函数不就成了吗?不过需要添个LPSHFILEOPSTRUCT <br>结构,具体怎么用,msdn会帮你的。呵呵
 
昨天本想请你吃田螺的。可惜回来太晚了。:)
 
DOS/Windows下的参数符应该是 "/", 而且参数之间用空格分割.<br>运行程序最好是使用ShellExecute<br><br>而且deltree的时候要注意程序的当前路径不是要删除的路径.比如:<br><br>c:/temp&gt; deltree /y c:/temp<br><br>就可能会出错.
 
The RemoveDirectory function deletes an existing empty directory. <br>BOOL RemoveDirectory( LPCTSTR lpPathName<br>&nbsp; // address of directory to remove);<br>我的通过了!<br>RemoveDirectory('C:/Program Files/Borland/Delphi5/'<br>&nbsp; +'Projects/test/Udp/新建文件夹'); <br>还过如果有子文件夹就删不了。你可以做一个函数一个一个的删呀。:)<br>或者有其它办法吧我就知道这么多了不好意思
 
pyh_jerry 啊,这个文件夹下面有1000张图片,还能用这个删除?
 
给你写一个吧,不过错误控制要自己加一下<br>Function DelTree(Path:String):Boolean;<br>Var<br>&nbsp; &nbsp;Found:Integer;<br>&nbsp; &nbsp;SearchRec:TSearchRec;<br>begin<br>&nbsp; &nbsp; Found := FindFirst(path+'*.*', $0000003F, SearchRec);<br>&nbsp; &nbsp; While Found = 0 Do<br>&nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If ((SearchRec.Name&lt;&gt;'.') &nbsp;And (SearchRec.Name&lt;&gt;'..') )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If (SearchRec.Attr = $00000010)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DelTree(Path+SearchRec.Name+'/')<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DeleteFile(Path+SearchRec.Name);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Found := FindNext(SearchRec);<br>&nbsp; &nbsp; End;<br>&nbsp; &nbsp; FindClose(SearchRec);<br>&nbsp; &nbsp; RmDir(Path);<br>End;<br><br>DelTree('C:/Temp/');
 
建议用lww的方法,不过netwind的方法更有助于学习DELPHI
 
那个DELTREE的控件用起来可以吗?<br>呵呵,老千的口音,听起来,嘻嘻。。。
 
多人接受答案了。
 
后退
顶部