function DeleteDirectory(NowPath:String):Boolean; //删除整个目录
var
search:TSearchRec;
ret:integer;
key:string;
begin
if NowPath[Length(NowPath)]<>'\' then
NowPath:=NowPath+'\';
key:=Nowpath+'*.*';
ret:=findFirst(key,faanyfile,search);
while ret=0 do begin
if ((search.Attr and fadirectory)= faDirectory)
then begin
if (Search.Name <>'.') and (Search.name<>'..') then
DeleteDirectory(NowPath+Search.name);
end else begin
if ((search.attr and fadirectory)<> fadirectory) then begin
deletefile(NowPath+search.name);
end;
end;
ret:=FindNext(search);
end;
findClose(search);
removedir(NowPath);
result:=True;
end;
var
search:TSearchRec;
ret:integer;
key:string;
begin
if NowPath[Length(NowPath)]<>'\' then
NowPath:=NowPath+'\';
key:=Nowpath+'*.*';
ret:=findFirst(key,faanyfile,search);
while ret=0 do begin
if ((search.Attr and fadirectory)= faDirectory)
then begin
if (Search.Name <>'.') and (Search.name<>'..') then
DeleteDirectory(NowPath+Search.name);
end else begin
if ((search.attr and fadirectory)<> fadirectory) then begin
deletefile(NowPath+search.name);
end;
end;
ret:=FindNext(search);
end;
findClose(search);
removedir(NowPath);
result:=True;
end;
解决方案 »
- win98下 indy UDP无法接受广播数据
- 谁来帮我找出这个错误
- 紧急求助,关于数据类型
- delphi exit的用法问题!
- 一个初学者的问题,请问在接口的private,public和var三处声明变量有什么不同呢?
- 我用dbedit控件连一个浮点数类型,它怎么就是不接受0啊!非零的数都可以,可是输入0它就不显示了,为什么啊?
- 各位好汉,加密算法竞赛!!前3名有分!
- 如果不使用ODBC,使用BDE能使应用程序连接Acess数据库吗?能使程序完成之后,经过install shield打包之后,在别的新机器上运行吗。
- 为什么线程不能重复使用?
- DAX error错误,紧急在线求助
- 三類型如何互相轉換:single , integer,string?
- 老千,你在那里???
var
SHFileOpStruct: TSHFileOpStruct;
DirName: PChar;
BufferSize: Cardinal;
begin
BufferSize := Length(ADirName) +1 +1;
GetMem(DirName, BufferSize);
try
FillChar(DirName^, BufferSize, 0);
StrCopy(DirName, PChar(ADirName)); with SHFileOpStruct do
begin
Wnd := AHandle;
wFunc := FO_DELETE;
pFrom := DirName;
pTo := nil;
fFlags := FOF_ALLOWUNDO; fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
end; if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
finally
FreeMem(DirName, BufferSize);
end;
end;
你的方法好象没有成功。
你的方法是作什么的?真的能失掉吗?
var
srPath: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := faAnyFile;
if findFirst(sPath + '\*.*', FileAttrs, srPAth) = 0 then
begin
repeat
if srPath.Attr = faDirectory then
begin
if (srPath.Name <> '.') and (srPath.Name <> '..') then
DeleteDirectory(sPath + '\' + srPath.Name);
end
else
begin
DeleteFile( sPath +'\'+ srPath.Name );
if IOResult <>0 then
showmessage('error:'+srPath.Name );
end;
until FindNext(srPath) <> 0;
FindClose(srPath);
end;
RmDir(sPath);
end;我的方法也可以.
大家交流交流。
hehe.
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:\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 direcotry:c:\test');
end;
var
SHFileOpStruct: TSHFileOpStruct;
DirName: PChar;
BufferSize: Cardinal;
begin
BufferSize := Length(ADirName) +1 +1;
GetMem(DirName, BufferSize);
try
FillChar(DirName^, BufferSize, 0);
StrCopy(DirName, PChar(ADirName)); with SHFileOpStruct do
begin
Wnd := AHandle;
wFunc := FO_DELETE;
pFrom := DirName;
pTo := nil;
fFlags := FOF_ALLOWUNDO; fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
end; if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
finally
FreeMem(DirName, BufferSize);
end;
end;
我的代码配合一个opendialog获取目录名称之后运行正常,怎么会不行呢?
在程序里面写一个.BAT文件,内容如下:
del XXX/*.*然后用Winexec执行这个.bat
大致如下winexec(pchar('delete \y '+pathtodel+'*.*'),sw_hide);