本文整理自网络,侵删。
/// 包含单元 uses FileCtrl
//获得文件列表
function GetAllTextFile(Path,fext: string): TStringList;
var
f: TSearchRec;
r: Integer;
begin
Result:=TStringList.Create;
if Path[Length(Path)]<>'\' then Path:=Path+'\';
r:=FindFirst(Path+fext, faAnyFile, f);
while r=0 do
begin
Result.Append(f.Name);
r:=FindNext(f)
end;
FindClose(f);
end;
//添加列表
procedure setlstbook(lst1:TListBox);
var
dir:string;
i,posx:integer;
filelst:TStringList;
begin
filelst:=TStringList.Create;
if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],1000) then
begin
filelst.Text:=GetAllTextFile(Dir,'*.txt').Text;
lst1.clear;
for i :=0 to filelst.Count-1 do
begin
posx:=Pos('.',filelstt.Strings[i]);
lst1.Items.Add(copy(filelst.Strings[i],1,posx-1));
end;
end;
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>