这个程序为什么不能执行啊?procedure TForm1.FormCreate(Sender: TObject);
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath = 'd:\*.*';
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(ExtractFilePath(szFilePath) + SearchRec.Name);
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
var
SearchRec: TSearchRec;
nResult: Integer;
const
szFilePath = 'd:\*.*';
//填充ListBox
ListBox1.Items.clear;
nResult:=FindFirst(szFilePath,faAnyFile,SearchRec); //查找第一个文件
while nResult = 0 do //如果返回值为0表示找到文件
begin
//将找到的文件添加到ListBox中;ExtractFilepath函数用于提取文件路径
ListBox1.Items.Add(ExtractFilePath(szFilePath) + SearchRec.Name);
nResult:=FindNext(SearchRec); //继续查找下一个文件,至到返回值不为0时
end;
解决方案 »
- 关于sql server 2000数据库并发问题,同时插入数据记录出现重复ID
- 问个网络通讯的网通
- delphi如何批量删除文件?
- 用文件系统(过滤)驱动程序开发(IFS) 动态加解密的方法(1000分)答谢,来者有分
- dbgrideh录入数据唯一性的问题。
- 在dbgrid中为什么备注型(或text型字段)的那一列总显示为(memo),其他字段类型对应的列正常。
- 超难查询语句,,,这样的记录查询如何写查询语句/.....
- 关于添加数据的问题,谢谢
- activeX控件是如何处理消息循环的(不够在加分)
- 怎样在已存的表中加入字段呀?用table,sql也要(从表一选择一个字段的内容为字段名
- INI文件中的VALUE值如果包含有空格,双引号应该怎么处理
- 建立一个局域网聊天程序,怎么做?高手请进,或者给个思路
SearchRec: TSearchRec;
Found: Integer;
begin
try
Found := FindFirst('d:\*.*', 0, SearchRec);
while Found = 0 do
begin
if (ExtractFileExt(SearchRec.Name)= '*.txt') then
ListBox1.Items.Add(SearchRec.Name);
Found := FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;
把*.*改称*.txt应该就是第二问的答案吧。
form create的时候listbox还没有出来呢,放到formshow里面。
把*.*改称*.txt应该就是第二问的答案吧。
==================
谁说的????????
1.如何在listbox中显示程序所在目录的文件名,即szFilePath需要赋值为相对目录名
2.如何只显示文件名,而不显示后缀.txt
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;
SearchRec: TSearchRec;
Found: Integer;
begin
try
Found := FindFirst('d:\*.*', 0, SearchRec);
while Found = 0 do
begin
if (ExtractFileExt(SearchRec.Name)= '*.txt') then
ListBox1.Items.Add(Copy(SearchRec.Name,1,Length(SearchRec.Name)-Length(ExtractFileExt(SearchRec.Name))));
Found := FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;