CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

文件的删除

楼主supershan()1999-12-29 10:26:00 在 Delphi / VCL组件开发及应用 提问

如果要删除一个目录,并且此目录下还有许多文件,要一起删除,请问用什么函数! 问题点数:50、回复次数:10Top

1 楼zdg(曾登高)回复于 1999-12-29 10:31:00 得分 0

好像没有现成的函数,   需要用遍历删除...Top

2 楼Bobo(bobo)回复于 1999-12-29 10:48:00 得分 0

var   str   string  
  winexec(deltree   str)Top

3 楼jiangtao(蒋涛)回复于 1999-12-29 11:16:00 得分 0

Use   Findfirst,FindNext   遍历目录,  
  the   use   RemoveFile   to   delete   files   you   findTop

4 楼chenzhuangyuan()回复于 1999-12-29 11:56:00 得分 0

用CFileFind类,遍历目录查找文件,再删除   Remove(FileName)。Top

5 楼kxy(手举穿肠毒药,怀抱刮骨钢刀)回复于 1999-12-29 13:07:00 得分 0

遍历,再删除  
  www.midatech/jiangtao下有TFileFinder的控件Open   Source,我放的,  
  用ftp工具可以下载.此控件很好用:)Top

6 楼util()回复于 1999-12-30 10:12:00 得分 0

现成函数没有。可以考虑调用外部程序。Windows   95/98和Dos中可用Deltree/y   [目录名],NT中用rd/s/q   [目录名],可以保证完全删除(NT下正在使用的文件不能删除,与之对应的子目录及父目录不能删除。)Top

7 楼tide(水手辛巴德)回复于 2000-01-02 18:50:00 得分 0

following   code   may   help   u:  
   
   
  --------------------------------------------------------------------------------  
     
  program   del;  
   
  uses  
    ShellApi;  
   
  //function   SHFileOperation(const   lpFileOp:   TSHFileOpStruct):   Integer;   stdcall;  
   
  Var   T:TSHFileOpStruct;  
          P:String;  
  begin  
      P:='C:\Windows\System\EL_CONTROL.CPL';  
      With   T   do  
      Begin  
          Wnd:=0;  
          wFunc:=FO_DELETE;  
          pFrom:=Pchar(P);  
          fFlags:=FOF_ALLOWUNDO  
      End;  
      SHFileOperation(T);  
  End.  
  --------------------------------------------------------------------------------  
  There   are   some   other   quirks   you   should   be   aware   of,   too:    
   
  Give   the   complete   file   path   for   every   file   specified.   Do   not   rely   on   the   current   directory,   even   if   you   change   to   it   right   before   the   call.   The   SHFileOperation   API   is   not   "smart"   enough   to   use   the   current   directory   if   one   is   not   given   for   undo   information.   So,   even   if   you   give   the   FOF_ALLOWUNDO   flag,   it   will   not   move   deleted   files   to   the   recycle   bin   because   it   doesn't   know   what   path   they   came   from,   and   thus   couldn't   restore   them   to   their   original   location   from   the   recycle   bin.   It   will   simply   delete   the   file   from   the   current   directory.    
   
  MS   has   a   documentation   correction   about   the   pFrom   member.   It   says   that   for   multiple   files,   each   filename   is   seperated   by   a   NULL   (#0)   character,   and   the   whole   thing   is   terminated   by   double   NULLs.   You   need   the   double   NULL   whether   or   not   you   are   passing   multiple   filenames.   Sometimes   it   will   work   correctly   without   them,   but   often   not.   That's   because   sometimes   you   get   lucky   and   the   memory   following   the   end   of   your   string   has   a   NULL   there.    
   
  An   example   of   how   to   do   this   would   be:  
   
  var  
      FileList:   string;  
      FOS:   TShFileOpStruct;  
  begin  
      FileList   :=   'c:\delete.me'#0'c:\windows\temp.$$$'#0#0;  
      {   if   you   were   using   filenames   in   string   variables:   }  
      FileList   :=   Filename1   +   #0   +   Filename2   +   #0#0;  
   
      FOS.pFrom   :=   PChar(FileList);  
   
      //   blah   blah   blah  
  end;  
  Top

8 楼zyb()回复于 2000-01-06 08:42:00 得分 0

定义一个TSEARCHRECT变量,然后用findfirst,findnext遍历目录,然后用deletefile(filename)即可删除该目录下的所有文件。似乎没有什么更好的方法!Top

9 楼fish()回复于 2000-01-06 11:35:00 得分 50

删除一子目录及其下面的文件  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
          DirInfo:   TSearchRec;  
          r   :   Integer;  
  begin  
          r   :=   FindFirst('C:\Download\Test\*.*',   FaAnyfile,   DirInfo);  
          while   r   =   0   do  
                  begin  
                          if   ((DirInfo.Attr   and   FaDirectory<>FaDirectory)   and  
                                (DirInfo.Attr   and   FaVolumeId<>FaVolumeID))   then  
                                      if   DeleteFile(pChar('C:\Download\test\'   +   DirInfo.Name))   =   false   then  
                                            ShowMessage('Unable   to   delete   :   C:\Download\test\'   +   DirInfo.Name);  
                          r   :=   FindNext(DirInfo);  
                  end;  
          SysUtils.FindClose(DirInfo);  
          if   RemoveDirectory('C:\Download\Test')   =   false   then  
                  ShowMessage('Unable   to   delete   direcotry   :   C:\Download\test');  
  end;  
  Top

10 楼supershan()回复于 2000-01-06 12:13:00 得分 0

fish的回答比较满意可以为你加分!Top

相关问题

  • 删除文件
  • 删除文件??
  • 文件删除
  • 删除文件
  • 删除文件
  • 删除文件
  • 删除文件夹
  • dll文件删除
  • 删除word文件
  • 如何删除文件?

关键词

  • 文件
  • 函数
  • 删除
  • dirinfo
  • 遍历
  • 目录
  • shfileoperation
  • download
  • delete
  • begin

得分解答快速导航

  • 帖主:supershan
  • fish

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo