这个程序为什么不能执行啊?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语句:以表中记录出现次数为序,从大到小依次将所有记录(重复记录只出现一次)列出来
- 登记薄:二零零六,您的期待和希望是什么?
- 动态SQL切换数据库的问题
- 大虾们,帮帮解决dll窗体调用的问题,分数不够可以在加
- DrawGrid控件的使用问题
- 请推荐一些DELPHI7.0的优秀控件,尤其是界面和皮肤的,高分相送!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 分辨率怎么处理啊?
- 急,救命~~~~~~~~~
- 请大侠帮忙推荐几本delphi好书,
- horlen(少爷的破拐杖),这1分是给你的,决不食盐!
- 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;