delphi 获取当前目录下的.txt文本不要带后缀扩展名

//获得文件列表
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;

/// 包含单元 uses  FileCtrl

转自:http://zhidao.baidu.com/question/181822404.html

posted @ 2012-05-20 14:33  stma  阅读(280)  评论(0)    收藏  举报