获取目录下所有文件名的代码
程序员文章站
2023-10-14 12:54:34
一:获取指定文件夹的文件 复制代码 代码如下: procedure searchfile(path:string);//注意,path后面要有'\'; var search...
一:获取指定文件夹的文件
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;