如何获取一个文件夹下的文件名列表
如上 问题点数:20、回复次数:2Top
1 楼shove(shove)回复于 2005-04-04 20:57:57 得分 20
你参考这个,这个是遍历某目录及其所有子目录、文件,并删除的函数。有你要的东西
procedure Fun_DeleteDir(sDirectory:String);stdcall;//删除目录和目录下得所有文件和文件夹
var
sr:TSearchRec;
sPath,sFile: String;
begin
if Copy(sDirectory,Length(sDirectory),1) <> '\' then
sPath := sDirectory + '\'
else
sPath := sDirectory;
if SysUtils.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
Fun_DeleteDir(sFile)
else
if (sr.Attr and faAnyFile) = sr.Attr then
begin
try
DeleteFile(PAnsiChar(sFile)); //删除文件
except
;
end;
end;
until SysUtils.FindNext(sr) <> 0;
SysUtils.FindClose(sr);
end;
try
RemoveDir(sPath);
except
;
end;
end;Top
2 楼codeuser(结果?)回复于 2005-04-05 10:52:06 得分 0
谢谢shove的帮助,祝你快乐Top




