获取目录下所有文件名的代码
(编辑:jimmy 日期: 2024/11/24 浏览:3 次 )
一:获取指定文件夹的文件
复制代码 代码如下:
procedure searchfile(path:string);//注意,path后面要有'\';
var
SearchRec:TSearchRec;
found:integer;
begin
found:=FindFirst(path+'*.*',faAnyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..')
and (SearchRec.Attr<>faDirectory) then
ListBox1.Add(SearchRec.Name);
found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
二:获取该目录下的子目录的文件
复制代码 代码如下:
procedure SearchFile(path:string);
var
SearchRec:TSearchRec;
found:integer;
begin
found:=FindFirst(path+'*.*',faAanyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.name<>'..) and
(SearchRec.Name=faDirectory) then
SearchFile(SearchRec.Name+'\')
else
LisBox1.Add(SearchRec.Name);
found:=FindNext(SearchREc);
end;
FindClose(SearchRec);
end;
复制代码 代码如下:
procedure searchfile(path:string);//注意,path后面要有'\';
var
SearchRec:TSearchRec;
found:integer;
begin
found:=FindFirst(path+'*.*',faAnyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.Name<>'..')
and (SearchRec.Attr<>faDirectory) then
ListBox1.Add(SearchRec.Name);
found:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
二:获取该目录下的子目录的文件
复制代码 代码如下:
procedure SearchFile(path:string);
var
SearchRec:TSearchRec;
found:integer;
begin
found:=FindFirst(path+'*.*',faAanyFile,SearchRec);
while found=0 do
begin
if (SearchRec.Name<>'.') and (SearchRec.name<>'..) and
(SearchRec.Name=faDirectory) then
SearchFile(SearchRec.Name+'\')
else
LisBox1.Add(SearchRec.Name);
found:=FindNext(SearchREc);
end;
FindClose(SearchRec);
end;
下一篇:windows 中 \r\n 区别于 类unix中的\n 疑问说明