原因比较多吧!
第一个不能删除的原因是我再搜索某指定目录下有什么文件时竟然少了这个语句
FINDCLOSE(TSearceRec),而这中程序我还不知道怎么调试他。(那位大虾能教我一下吗?)只能凭着ASP的代码看结果然后再猜原因.
其它程序(如dreamweaver)打开该文件出现共享错误也时这个原因!
第二个关于整个目录删除的问题。当用第归方法删除某一目录时最顶层的目录老删不钓。
我吧哪函数给改了。新的方法写得很菜,大家别见笑,如下:
function TFileManage.DelFolder(AFolder: OleVariant): OleVariant;
procedure DelAFolder(AFolder:string);
var
Found:integer;
SearchResult:TSearchRec;
begin
Found:=FindFirst(AFolder+'/*.*',faAnyFile,SearchResult);
while Found=0 do
begin
if (SearchResult.Name<>'.') and (SearchResult.Name<>'..') then
begin
if (SearchResult.Attr=faDirectory) then
DelAFolder(AFolder+'/'+SearchResult.Name)
else
begin
FileSetAttr(AFolder+'/'+SearchResult.Name,0);
DeleteFile(AFolder+'/'+SearchResult.Name);
end;
end;
Found:=FindNext(SearchResult);
end;
FindClose(SearchResult);
RmDir(AFolder);
end;
var
CDelF,UDelF:string;
Found:integer;
SearchResult:TSearchRec;
begin
try
Result:=1;
if FileGetAttr(AFolder)<>faDirectory then
begin
FileSetAttr(AFolder,0);
DeleteFile(AFolder);
exit;
end;{if FileGetAttr(AFolder)<>faDirectory then}
CDelF:=AFolder;
if Copy(CDelF,Length(CDelF),1)='/' then
CDelF:=Copy(CDelF,1,Length(CDelF)-1);
DelAFolder(CDelF);
SetCurrentDir(CDelF);
ChDir('..');
UDelF:=GetCurrentDir();//UDelF带'/'
Found:=FindFirst(UDelF+'*.*',faAnyFile,SearchResult);
while Found=0 do
begin
if (UDelF+SearchResult.Name=CDelF) then
begin
RmDir(CDelF);
break;
end;
Found:=FindNext(SearchResult);
end;
FindClose(SearchResult);
except
Result:=0;
end;
end;