//获取一个文件夹下的所有文件
//不包括文件夹里面的文件
//ListBox1.Items:= searchfile('Z:\'); //注意,path后面要有'\'; function Searchfile(path:string):TStringList;
var SearchRec:TSearchRec; found:integer; begin Result:=TStringList.Create; found:=FindFirst(path+'*.*',faAnyFile,SearchRec); while found=0 do begin
if (SearchRec.Name<>'.') and(SearchRec.Name<>'..') and (SearchRec.Attr<>faDirectory) then
Result.Add(SearchRec.Name);
found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
//搜索1个文件下面的文件 // GetDirFiles (ListView1,'Z:\aa\2013-06-23\');
procedure GetDirFiles(ListView:TListView;path: string;fileter:string='*.*');
var SearchRec: TSearchRec; found: integer; begin ListView.Items.Clear;
found := FindFirst(path + fileter, faAnyFile, SearchRec);
while found = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') and (SearchRec.Attr <> faDirectory) then
ListView.Items.Add.Caption:=SearchRec.Name; found := FindNext(SearchRec); end;
FindClose(SearchRec); end;
上面一个只获取当前目录下所有文件,如果要获取该目录下的子目录的文件,看下面
|
请发表评论