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 xe7里面 sharedactivitycontext怎么提示错误?

Delphi获取access中的表名代码

Delphi 几个和当前路径相关的新函数

Delphi 复制动态数组

Delphi trim 删除字符串左右两边的空格

Delphi源码webbrowser多次执行documentcomplete

Delphi 中打开浏览器跳转网址链接网页的几种方法

Delphi xe5实现的一个阳历转换成阴历的代码

Delphi中关闭“返回值…可能未定义”的警告

Delphi中三种延时方法

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



打赏

取消

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

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

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

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

评论

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