1.如何在listbox中显示程序所在目录的文件名,即szFilePath需要赋值为相对目录名
2.如何只显示文件名,而不显示后缀.txtprocedure TForm1.FormShow(Sender: TObject);
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath = 'd:\*.txt';
begin
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(SearchRec.Name);
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;
2.如何只显示文件名,而不显示后缀.txtprocedure TForm1.FormShow(Sender: TObject);
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath = 'd:\*.txt';
begin
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(SearchRec.Name);
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;
解决方案 »
- 主程序如何传递登陆信息及数据库连接COnnection信息传给DLL
- DELPHI链接MYSQL问题急急急
- 怎样用Delphi将sql自定义函数加入到数据库中?
- 如何在多个combobox控件之间用回车键和上下箭头键进行切换
- 请问的delhi中的包含字符串函数是那个,如何用?
- 请问如何得到buttom按下前的控件,高分奉上.
- 关于局域网内的邮件收发问题
- 一个巨重要的问题!
- 如何将edit里的输入自右向左顺序,就象计算器的显示一样。
- 高分相送!哪位仁兄讲讲LIBRARY PATH 的用处
- 关于showModal后返回值为True或False的问题?
- 紧急求救:有关F2Book的标题部分无法打印问题
2。将 ListBox1.Items.Add(SearchRec.Name);改为
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-POS('.',SearchRec.Name)+1);
Form1: TForm1;
i:integer = 1;
sss: Array [1..10] of string;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
SearchRec:tSearchRec;
FindResult:integer;
begin
FindResult := FindFirst('C:\top\'+ '*.txt',FaAnyFile,SearchRec);
while findresult=0 do
begin
listbox1.items.Add(ChangeFileExt(SearchRec.Name,''));
sss[i]:='C:\top\'+SearchRec.Name;
i:=i+1;
FindResult :=findnext(Searchrec);
end;
end;procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
if listbox1.Selected[listbox1.ItemIndex]=true then
begin
edit1.Text:=sss[listbox1.ItemIndex+1];
end
else
Exit;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShow(Sender: TObject);
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath =Application.EXEName+'\*.txt';
begin
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-POS('.',SearchRec.Name)+1));
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;end.
var
SearchRec: TSearchRec;
s:string;
nResult: Integer;
//const
//szFilePath =ExtractFilePath(Application.ExeName));begin
//填充ListBox
s:=ExtractFilePath(Application.ExeName)+'\*.txt';
ListBox1.Items.clear;
nResult:=FindFirst(s,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-4));
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;
var
SearchRec: TSearchRec;
ss:string;
nResult: Integer;
//const
//szFilePath =ExtractFilePath(Application.ExeName));begin
//填充ListBox
ss:=s+'\*.txt';
ListBox1.Items.clear;
nResult:=FindFirst(ss,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-4));
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
end;凋用:
self.showfile('d:\aa');