procedure TForm1.Button1Click(Sender: TObject);
var dirinfo:tsearchrec;r:integer;
begin
r:=SysUtils.FindFirst('c:\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:\test\'+dirinfo.name))=false then
showmessage('unable to delete:c:\test\'+dirinfo.name);
r:=findnext(dirinfo);
end;
sysutils.findclose(dirinfo);
if removedirectory('c:\test')=false then
showmessage('unable to delete:c:\test');
end;
var dirinfo:tsearchrec;r:integer;
begin
r:=SysUtils.FindFirst('c:\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:\test\'+dirinfo.name))=false then
showmessage('unable to delete:c:\test\'+dirinfo.name);
r:=findnext(dirinfo);
end;
sysutils.findclose(dirinfo);
if removedirectory('c:\test')=false then
showmessage('unable to delete:c:\test');
end;
解决方案 »
- 怎么把ACCESS中的一张表的数据包括字段标题都导入EXCEL里去?
- 如果用TCP方式做服务器,怎么维护在线用户?
- 散分!鳖在心中2年的话终于说出来了,并取得了意想不到的结果!
- 窗体上的label, button上的caption文字显示‘???’
- 一个多线程的问题,请指教
- combobox 的text,value是怎样用的?
- 提供D5 Enterprise下载,要下的赶快行动,用Daemon打开
- 求助
- 请高手解答
- 还收使用delphi的朋友吗?请教个问题:两个服务器开机启动,服务B需要依赖服务A才能启动,需要做什么特别处理吗?
- 请教各位大虾:怎么才能动态生成一个TFrame的实例?
- 请推荐一本专讲DELPHI中OOP的书。
var dirinfo:tsearchrec;r:integer;
begin
r:=SysUtils.FindFirst('c:\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:\test\'+dirinfo.name))=false then
showmessage('unable to delete:c:\test\'+dirinfo.name);
r:=findnext(dirinfo);
end;
sysutils.findclose(dirinfo);
if removedirectory('c:\test')=false then
showmessage('unable to delete:c:\test');
end;
删除目录的递归辅助函数:DoRemoveDir
function DoRemoveDir(sDirName:String):Boolean;varhFindFile:Cardinal;tfile:String;sCurDir:String;bEmptyDir:Boolean;FindFileData:WIN32_FIND_DATA;begin//如果删除的是空目录则置bEmptyDir为True//初始时bEmptyDir为TruebEmptyDir:=True;//先保存当前目录sCurDir:=GetCurrentDir;SetLength(sCurDirLength(sCurDir));ChDir(sDirName);hFindFile:=FindFirstFile('*.*'FindFileData);if hFindFile< >INVALID_HANDLE_VALUE thenbeginrepeattfile:=FindFileData.cFileName;if (tfile='.') or (tfile='..') thenbeginbEmptyDir:=bEmptyDir and True;Continue;end;//不是空目录置bEmptyDir为FalsebEmptyDir:=False;if FindFileData.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY thenbeginif sDirName[Length(sDirName)]< >'\' thenDoRemoveDir(sDirName+'\'+tfile)elseDoRemoveDir(sDirName+tfile);if not RemoveDirectory(PChar(tfile)) thenresult:=falseelseresult:=true;endelsebeginif not DeleteFile(PChar(tfile)) thenresult:=falseelseresult:=true;end;until FindNextFile(hFindFileFindFileData)=false;FindClose(hFindFile);endelsebeginChDir(sCurDir);result:=false;exit;end;//如果是空目录则删除该空目录if bEmptyDir thenbegin//返回上一级目录ChDir('..');//删除空目录RemoveDirectory(PChar(sDirName));end;
//回到原来的目录下ChDir(sCurDir);result:=true;end;删除目录的函数:DeleteDir
function DeleteDir(sDirName:String):Boolean;beginif Length(sDirName)< =0 thenexit;//删除...Result:=DoRemoveDir(sDirName) and RemoveDir(sDirName);end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var F:TShFileOpStruct; //uses shellapi;
b:integer;
begin
f.Wnd:=Form1.Handle;
f.wFunc:=fo_delete;
f.pFrom:=pChar('c:\windows\desktop\test');
f.fFlags:=FOF_ALLOWUNDO or FOF_NOCONFIRMATION;
b:=ShFileOperation(f);
if b=0 then exit;
beep; ShowMessage('文件操作没有实现!');
end;