Solved

searching for *.lang

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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