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; 请教memo的lines用for循环的赋值问题。 如何返回ShellListView选中的文件名? 请问:拖放中被接收对象事件里的鼠标的坐标如何转换到被接收对象的相对坐标? delphi如何调用oracle的存储过错并返回记录集 是不是QucikRep的BUG? 一个关于回车代替TAB的问题!纯粹送分!快来呀! 关于post 寻求(client)socket对远程主机多线程查询的例子 从哪里可以下载Delphi for linux 版本呢?相关资料又在哪里有? Form为什么不能显示画面 关于制作安装程序 求助
如果不知道就可以用: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;