求在DELPHI中删除非空文件夹的思路及源码?!我要在程序中删除某些文件夹。给个思路及源码!谢谢![email protected]
解决方案 »
- 如何实现PopupMenu菜单中的菜单项可以拖动
- 请问,如何可以让一个应用程序只可以在一台机器上运行?在线等待 .......
- 请问基于ADO的应用程序可以是单层的或多层的?其情况取决于使用的?
- 急! Delphi如何实现DataChunk?
- 我想对指定多个文件进行复制、覆盖,该如何实现?
- 关于绑定,有心者进去看一下
- 在做webservice时,最简单的对数据库插入和删除方法是什么?
- Sockets编程:如何在对等网中自动获取在线的计算机名列表?
- 请问哪里有Mybase格式软件下载??急用!急用!急用!急用!
- 三个表组成的主细表关系,显示问题!!!!
- 用ttcpClient不能触发onreceive事件
- ---》俺对这个问题都追加到三百分了,高手看了别跑!!!!
//删除子目录及其下文件//This doesn't check for attributes being set, which might preclude deletion of a file. Put a {$I-} {$I+} pair around the functions that cause the problem.procedure removeTree (DirName: string);
var
FileSearch: tSearchRec;
begin
{ first, go through and delete all the directories }
chDir (DirName);
FindFirst ('*.*', faDirectory, FileSearch);
while (getlastError = 0) do
begin
if (FileSearch.name <> '.')
AND (FileSearch.name <> '..')
AND ((FileSearch.attr AND faDirectory) <> 0)
then begin
if DirName[length(DirName)] = '\' then
removeTree (DirName+FileSearch.Name)
else
removeTree (DirName+'\'+FileSearch.Name);
ChDir (DirName);
end;
FindNext (FileSearch)
end;
{then, go through and delete all the files }
FindFirst ('*.*', faAnyFile, FileSearch);
while (getlastError = 0) do
begin
if (FileSearch.name <> '.')
AND (FileSearch.name <> '..') then
deletefile(FileSearch.name); //Remove和WorkDir是何意,删除文件?
FindNext (FileSearch)
end;
rmDir (DirName) //应进入上层目录
end;
----------
procedure TForm1.Button7Click(Sender: TObject);
var
sh:TSHFileOpStruct;
begin
sh.Wnd :=Handle;
sh.pFrom:=PChar('D:\复件 TCWork');
sh.wFunc:=FO_DELETE ;
sh.fFlags:=FOF_SIMPLEPROGRESS ;
sh.lpszProgressTitle:=Pchar('Delete File');
SHFileOperation(sh);
end;
快捷、方便
我的磁盘格式是NTFS。我用的DELPHI 是7!
http://www.djtz.net/get.asp?get=9662