如何在Delphi里删除文件夹?

bjbs_vb 2005-03-22 04:17:00
如何在Delphi里删除文件夹?,文件夹中所有文件一起删除.
有通用涵数最好,
或给代码列子.



...全文
891 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bjbs_vb 2005-03-22
  • 打赏
  • 举报
回复
谢谢大家了.
solokey(永远的菜鸟-努力的学习ing-数据库太弱,被鄙视) ()
ly_liuyang(Liu Yang) ()
firstshine(黑里透红) ()
他们的方法估计都可以,先顶两天再结,让更多的象我一样的新手看看.
hellolongbin 2005-03-22
  • 打赏
  • 举报
回复
但只能对空文件夹管用
要先用DeleteFile()删除里面的文件
hellolongbin 2005-03-22
  • 打赏
  • 举报
回复
一句话:removedir('c:\tmp\')
firstshine 2005-03-22
  • 打赏
  • 举报
回复
procedure DeleteDir(sDirectory: String);
//删除目录和目录下得所有文件和文件夹
var
sr: TSearchRec;
sPath,sFile: String;
begin
//检查目录名后面是否有 '\'
if Copy(sDirectory,Length(sDirectory),1) <> '\' then
sPath := sDirectory + '\'
else
sPath := sDirectory;

//------------------------------------------------------------------
if FindFirst(sPath+'*.*',faAnyFile, sr) = 0 then
begin
repeat
sFile:=Trim(sr.Name);
if sFile='.' then Continue;
if sFile='..' then Continue;

sFile:=sPath+sr.Name;
if (sr.Attr and faDirectory)<>0 then
DeleteDir(sFile)
else if (sr.Attr and faAnyFile) = sr.Attr then
DeleteFile(sFile); //删除文件
until FindNext(sr) <> 0;
FindClose(sr);
end;
RemoveDir(sPath);
//------------------------------------------------------------------
end;
ly_liuyang 2005-03-22
  • 打赏
  • 举报
回复
ShellAPI:
SHFileOperation

这类问题N次啦

http://lysoft.7u7.net
solokey 2005-03-22
  • 打赏
  • 举报
回复
API
SHFileOperation

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧