如何按文件名(按时间命名)检索某一固定文件夹下的文件(100分)

  • 主题发起人 主题发起人 tianzhegs
  • 开始时间 开始时间
T

tianzhegs

Unregistered / Unconfirmed
GUEST, unregistred user!
在一个固定文件夹下,有一些按年月日分小时秒命名的文件,我现在想在一个edit框中添上
文件名就搜索出该文件,那位高手帮我解决一下.谢谢
 
var
SearchRec: TSearchRec;
begin
if FindFirst('C:/WINDOWS/*.INI', attributes, SearchRec) = 0 then
begin
repeat
// 这里我们处理找到的每一个文件。
// 它的消息在SearchRec中。
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
 
转贴
Function TForm1.GetFileNum(path:string) : integer; //在目录下查找文件;
var
rec:Tsearchrec;
begin
Result := 0;
if Findfirst(path+'*.*',faAnyFile,rec)=0 then
begin
if (UpperCase(ExtractFileExt(rec.name))='.BMP') then
Result:=result+1;
while FindNext(rec) = 0 do
begin
if (UpperCase(ExtractFileExt(rec.name))='.BMP') then
begin
inc(Result) ;
end;
application.ProcessMessages;
end;
findclose(rec);
end;
end;
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl, StdCtrls;

type
TForm1 = class(TForm)
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
FilterComboBox1: TFilterComboBox;
Edit: TEdit;
Button1: TButton;
procedure FileListBox1Change(Sender: TObject);
procedure DriveComboBox1Change(Sender: TObject);
procedure DirectoryListBox1Change(Sender: TObject);
procedure FilterComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure EditKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
searched:boolean;
implementation

{$R *.DFM}

procedure TForm1.FileListBox1Change(Sender: TObject);
begin
DirectoryListBox1.Drive:=DriveComboBox1.Drive;
FileListBox1.Drive:=DriveComboBox1.Drive;
FileListBox1.Directory:=DirectoryListBox1.Directory;
DriveComboBox1.Drive:='c';
DirectoryListBox1.Directory:='c:/video';
end;

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DriveComboBox1.Drive:='c';
end;

procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
DirectoryListBox1.Directory:='c:/video';
end;

procedure TForm1.FilterComboBox1Change(Sender: TObject);
begin
FileListBox1.Mask:=FilterComboBox1.Mask;
FileListBox1:=FilterComboBox1.FileList;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
searchrec:tsearchrec;
begin
searched:=true;
filelistbox1.Items.Clear;
findfirst(edit.text+'*.mpg',faanyfile,searchrec);
filelistbox1.Items.Add(searchrec.name);
while findnext(searchrec)=0 do
filelistbox1.Items.Add(searchrec.name);
end;

procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
button1click(sender);
end;

end.
 
用ugvanxk的方法吧
 
多人接受答案了。
 
后退
顶部