Solved

searching for *.lang

Posted on 2003-11-17
4
261 Views
Last Modified: 2012-05-04
I want to look for any files with the extension .lang in a specified directory and and display the filenames without the extensions in a combo-box.

Can anyone plz give me some advice on how to do this ?

Thx in advance
0
Comment
Question by:Professor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 125 total points
ID: 9764650
Try this:
procedure GetFileList( FileList: TStringList; inDir, Extension : String );
  procedure ProcessSearchRec( aSearchRec : TSearchRec );
  var
    sDate: String;
    w32fd: TWin32FindData;
    fct: TFileTime;
  begin
     if ( aSearchRec.Attr and faDirectory ) <> 0 then
     begin
       if ( aSearchRec.Name <> '.' ) and
          ( aSearchRec.Name <> '..' ) then
       begin
         GetFileList( FileList, Extension, InDir + '\' + aSearchRec.Name );
       end;
    end
    else
    begin
      FileList.Add(aSearchRec.Name);
    end;
  end;
var
  CurDir : String;
  aSearchRec : TSearchRec;
begin
  CurDir := inDir + '\' + Extension;
  if FindFirst( CurDir, faAnyFile, aSearchRec ) = 0 then
  begin
    ProcessSearchRec( aSearchRec );
    while FindNext( aSearchRec ) = 0 do
      ProcessSearchRec( aSearchRec );
  end;
end;

procedure TForm1.FormShow(Sender: TObject);
var
 FL: TStringList;
begin
 FL := TStringList.Create;
 FL.Sorted := True;
 GetFileList( FL, 'c:\eddie', '*.lang' );
 ComboBox1.Items.Assign(FL);
 FL.Free;
end;

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9764661
You will have to cut the extesnions of the filename when adding to the FileList, I forgot to do that.
0
 

Author Comment

by:Professor
ID: 9764673
I'll try ... thx
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9765420
To cut the extension off:
var s : string;
s := ExtractFileName(aSearchRec.Name);
s := Copy(s, 1, Length(s) - Length(ExtractFileExt(s));

Geoff M.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question