Solved

searching for *.lang

Posted on 2003-11-17
4
256 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Splash screen too shortlived 11 113
PDF files into SQL 2008 Varbinary(Max) 3 81
Magic Software info 18 105
Reconfigure Delphi Install? 2 37
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now