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


本文整理自网络,侵删。

 
/// 包含单元 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 字符串适宽处理

Delphi 基础计算两数之合

Delphi 计算运行耗时的方法1

Delphi 列出所有可视窗口

Delphi firedac,ado性能测试

Delphi如何过xp的防火墙而不被拦截

Delphi closefile 关闭文件

Delphi 2010 域名转换ip

Delphi 去掉mdi窗口的滚动条

Delphi 注入win7的单元

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...