Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

filelist

Posted on 1998-10-28
5
Medium Priority
?
307 Views
Last Modified: 2010-04-06
How can i get a list of all files of a directory inclusive
all files in the subdirectories with full pathname as
- an array of strings or
- items of a listbox or
- lines of a memo

rgds. T. Zigan
0
Comment
Question by:tzigan
[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
  • 2
5 Comments
 

Author Comment

by:tzigan
ID: 1344707
Edited text of question
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 600 total points
ID: 1344708
tzigan

here is a unit that shoes how to use TsearchRec to scan thourgh files and directories

unit Findfile;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure FileFind(StartingDirectory, FileName: string; FilesFound: TStringList);

  procedure SearchTree;
  var
    SearchRec: TSearchRec;
    DosError: integer;
    dir: string;
  begin
    GetDir(0, dir);
    if dir[length(dir)] <> '\' then dir := dir + '\';
    DosError := FindFirst(FileName, 0, SearchRec);
    while DosError = 0 do begin
      try
        FilesFound.add(dir + SearchRec.name);
      except
        on EOutOfResources do begin
          ShowMessage('Too many files.');
          abort;

        end;
      end;
      DosError := FindNext(SearchRec);
    end;
    {Now that we have all the files we need, lets go to a subdirectory.}
    DosError := FindFirst('*.*', faDirectory, SearchRec);
    while DosError = 0 do begin
      {If there is one, go there and search.}
      if ((SearchRec.attr and faDirectory = faDirectory) and
        (SearchRec.name <> '.') and (SearchRec.name <> '..')) then begin
        ChDir(SearchRec.name);
        SearchTree; {Time for the recursion!}
        ChDir('..'); {Down one level.}

      end;
      DosError := FindNext(SearchRec); {Look for another subdirectory}
    end;
  end; {SearchTree}

begin
  FilesFound.clear;
  ChDir(StartingDirectory);
  SearchTree;
end; {FileFind}

procedure TForm1.Button1Click(Sender: TObject);
var
  t: TStringList;
begin
  t := TStringList.create;
  FileFind(edit2.text, edit1.text, t);
  listbox1.items.assign(t);
  t.free;
end;

end.

Thanx to Lloyd for this

Later
BoRiS
0
 

Author Comment

by:tzigan
ID: 1344709
Please what means
{$R *.DFM}
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344710
tzigan

that just means include all the .dfm files which are the delphi form files it's standard when a unit is created in delphi...

Later
BoRiS
0
 
LVL 1

Expert Comment

by:jecksom
ID: 1344711
Tzigan , press F1  key rigth on $R compiler directive. Jecksom
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

610 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