delphi中如何取文件名 各位高手:請教在delphi中怎樣根據路徑取得該路徑下的文件名呢?急!急! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果知道文件名就可以用:ExtractFilename(s);如果不知道就可以用:FileListBox来加载数径里的文件列表,文件名:FileListBox.items[0]; s :=path;filename :=ExtractFileName(s); 楼上的方法得到的文件名包含扩展名~如果只想得到文件名~可以用 s := path;FileName := ChangeFileExt(ExtractFileName(s), '')以下给出我写的一个软件中枚举目录下所有.txt文件~并将文件名存储到指定文件中的过程~Path为路径~ListName是输出列表文件的文件名(不含扩展名)~*.txt为搜索文件的类型~楼主看着改吧~procedure TForm1.PreFileList(Path: string; ListName: string);var SR: TSearchRec; FileAttr: Integer; buf: TStringList;begin buf := TStringList.Create; FileAttr := faAnyFile; FindFirst(Path + '\*.txt', FileAttr, SR); if (SR.Name <> '.') and (Sr.Name <> '..') then buf.Add(ChangeFileExt(SR.Name, '')); while FindNext(SR) = 0 do begin if (SR.Name <> '.') and (Sr.Name <> '..') then if not (DirectoryExists(Path + '\' + SR.Name)) then buf.Add(ChangeFileExt(SR.Name, '')); end; buf.SaveToFile(AppDir + ListName + '.tmp'); buf.Free;end; COM书籍 年前升星,明天回家,买到黄牛票,鄙视中国铁道部!!! 【倒分投诉】请关注dbyzxf(毒草) 散分!!!! 高薪诚聘DELPHI高手 除使用Hook外,还有重定义键盘的方法吗? 如何使用TQuery控件用update语句更新mysql数据库? 请问在DEPHI中怎样实现文本文件导入导出SQL SERVER数据库? delphi如何和VC扯上关系?(一个ppmm的问题) 万分火急,请教访问数据库速度问题!多谢!!! 关于制作安装程序 求助
如果不知道就可以用:FileListBox来加载数径里的文件列表,文件名:FileListBox.items[0];
filename :=ExtractFileName(s);
如果只想得到文件名~
可以用
s := path;
FileName := ChangeFileExt(ExtractFileName(s), '')以下给出我写的一个软件中枚举目录下所有.txt文件~
并将文件名存储到指定文件中的过程~
Path为路径~
ListName是输出列表文件的文件名(不含扩展名)~
*.txt为搜索文件的类型~
楼主看着改吧~procedure TForm1.PreFileList(Path: string; ListName: string);
var
SR: TSearchRec;
FileAttr: Integer;
buf: TStringList;
begin
buf := TStringList.Create;
FileAttr := faAnyFile;
FindFirst(Path + '\*.txt', FileAttr, SR);
if (SR.Name <> '.') and (Sr.Name <> '..') then
buf.Add(ChangeFileExt(SR.Name, ''));
while FindNext(SR) = 0 do
begin
if (SR.Name <> '.') and (Sr.Name <> '..') then
if not (DirectoryExists(Path + '\' + SR.Name)) then
buf.Add(ChangeFileExt(SR.Name, ''));
end;
buf.SaveToFile(AppDir + ListName + '.tmp');
buf.Free;
end;