各位高手:請教在delphi中怎樣根據知道的路徑去找該路徑上的文件名呢?急!急!
解决方案 »
- 编程小混混有点不懂
- 多元方程求解的代码(求源代码)?
- ★★★ 招聘Delphi程序员1名。不知道在这里发贴是否违反规定
- 如何让一个edit控件添满后,光标自动移动到另一个edit控件中
- 请教:有没有计算两个时间相隔多少天或小时的函数?
- 求DBEDIT输入格式化的简单问题!!!
- 请问 PB和Delphi那一个更有“钱“途?
- 最近做一个防作弊系统,各位有没有关于win32 hooks得资料?谢谢!
- TMemo可以设置背景图片吗?
- sqlserver7的一个问题!!!!!很急!
- 为什么一打开D5后,主菜单被隐藏了,怎样才能把它调出来呢?急呀...........
- 请教一下delphi和oracle的区别。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, FileCtrl, ComCtrls;type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
FNewPath: string;
procedure DoSearchPathFile(qPath: string);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
DoSearchPathFile(Edit1.Text);end;procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;procedure TForm1.DoSearchPathFile(qPath: string);
var
SR: TSearchRec;
FileAttr: Integer;
begin
FileAttr := faDirectory;
FindFirst(qPath + '\*.*', FileAttr, SR); While FindNext(SR) = 0 do
begin
if (SR.Name <> '.') and (SR.Name <> '..') then begin
if DirectoryExists(qPath + '\' + SR.Name) then
begin
ListBox1.Items.Add('路径'+ qPath + '\' + SR.Name);
DoSearchPathFile(qPath + '\' + SR.Name); end;
//;else ListBox1.Items.Add(qPath + '\' + SR.Name); end;
end; FileAttr := faAnyFile; FindFirst(qPath + '\*.*', FileAttr, SR);
while FindNext(SR) = 0 do
begin
if (SR.Name <> '.') and (Sr.Name <> '..') then
begin
if not(DirectoryExists(qPath + '\' + SR.Name)) then
ListBox1.Items.Add(qPath + '\' + SR.Name);
end;
end;
end;procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin if key = vk_Return then
begin
if Trim(Edit1.Text) = '' then
begin
ShowMessage('Invalid PathName');
Exit;
end; FNewPath := Edit1.Text[Length(Edit1.Text)];
if FNewPath = '\' then
FNewPath := Copy(Edit1.Text, 1, Length(Edit1.Text) - 1)
else
begin
FNewPath := Edit1.Text;
end; ListBox1.Clear;
DoSearchPathFile(FNewPath); end;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
self.ListBox1.Items.SaveToFile('FileList.txt');
end;end.