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;
SHFileOperation这类问题N次啦http://lysoft.7u7.net
//删除目录和目录下得所有文件和文件夹
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;
要先用DeleteFile()删除里面的文件
solokey(永远的菜鸟-努力的学习ing-数据库太弱,被鄙视) ()
ly_liuyang(Liu Yang) ()
firstshine(黑里透红) ()
他们的方法估计都可以,先顶两天再结,让更多的象我一样的新手看看.