Board index » delphi » Filelist

Filelist

Hi!

I want to display all files from a directory including subdirectories in a
listbox or memo. The items in the box should display the complete filename
with path.

Any ideas?
Thanks in advance.

Matthias.

 

Re:Filelist


Hi! Try this

Use with care - consumes a lot of memory

Regards

        //Peter Glimstedt

const
  faAllFiles= faReadOnly or faHidden or faSysFile or faArchive;

  procedure Run;
  var
    Error: Integer; // Global to save space

    procedure GetAllFiles(Dir: String);
    var
      SR: TSearchRec;
      NewDir: String;
    begin
      NewDir:= Dir+'*.*'; // Alter this to change file type to find
      Error:= FindFirst(NewDir, faAllFiles, SR);
      while Error=0 do
      begin
        {Check if exiting}
//        if Something then
//          Exit;
        {Process the messages}
        Application.ProcessMessages;
        NewDir:= Dir+SR.Name;
        {Insert file to list}

// Here you have the name and path in NewDir
// Store it some where you like (Listbox maybe)

        {Get next}
        Error:= FindNext(SR);
      end; {while}
      FindClose(SR);
      NewDir:= Dir+'*.*';
      Error:= FindFirst(NewDir, faDirectory, SR);
      while Error=0 do
      begin
        {Check if exiting}
//        if Something then
//          Exit;
        {Process the messages}
        Application.ProcessMessages;
        if (SR.Attr and faDirectory<>0) and (SR.Name[1]<>'.') then
        begin
          NewDir:= Dir+SR.Name+'\';
          GetAllFiles(NewDir);
        end;
        Error:= FindNext(SR);
      end; {while}
      FindClose(SR);
    end; {GetAllFiles}

begin // Run
  GetAllFiles('C:\');

Quote
Matthias Meinecke wrote:
> Hi!

> I want to display all files from a directory including subdirectories in a
> listbox or memo. The items in the box should display the complete filename
> with path.

> Any ideas?
> Thanks in advance.

> Matthias.

Re:Filelist


Look at
 FindFirst
 FindNext
 FindClose.
Quote
Matthias Meinecke wrote in message <8r9nm3$do...@news.online.de>...
>Hi!

>I want to display all files from a directory including subdirectories in a
>listbox or memo. The items in the box should display the complete filename
>with path.

>Any ideas?
>Thanks in advance.

>Matthias.

Re:Filelist


On Mon, 02 Oct 2000 13:34:21 +0200, Peter Glimstedt

Quote
<p...@chl.chalmers.se> wrote:
>Hi! Try this

>Use with care - consumes a lot of memory

>Regards

>        //Peter Glimstedt

Hi,
Why does it use so much memory ? Is it possible to save some ?

Actually I usea similar routine to fill up a TStringGrid first then a
TRichEdit (w/ some formatting). Is there any way to limit ressources
consumption ? To speed up TRichEdit.lines.add (takes longer that
filesearch) ?

Thanx in adavnce,
Damien

Re:Filelist


"Damien" <NOSPAMdwor...@chez.comNoSpam> skrev i melding
news:39e56865.1371785@news.m6net.fr...

Quote
> On Mon, 02 Oct 2000 13:34:21 +0200, Peter Glimstedt
> <p...@chl.chalmers.se> wrote:

> >Hi! Try this

> >Use with care - consumes a lot of memory

> >Regards

> >        file://Peter Glimstedt

> Hi,
> Why does it use so much memory ? Is it possible to save some ?

It takes a lot of memory to store full path to all files (if so is
done):

C:\Program Files\Borland\Delphi5\bin\delphi32.exe

...,e.g., some 50 characters. You'll use 1Mb of ram for every 20,000 of
those.

Find a way to save paths only once....

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Filelist


Quote
"Bj?rge S?ther" <REMOVE_bsaether@THIS_online.no> wrote in message

news:p8kF5.4333$W31.65652@news1.online.no...

Quote
> > Hi,
> > Why does it use so much memory ? Is it possible to save some ?

> It takes a lot of memory to store full path to all files (if so is
> done):

> C:\Program Files\Borland\Delphi5\bin\delphi32.exe

> ...,e.g., some 50 characters. You'll use 1Mb of ram for every 20,000 of
> those.

> Find a way to save paths only once....

His best bet would be to use a tTreeView a la Explorer.

Given that he wants to use a listbox the original poster could store the
path in the Items.Objects array as strings and Owner Draw the list. If I
understand Delphi's long string handling this should reduce memory
consumption since all entries in a directory would reference the same
reference counted string. Of course the strings would have to be released
before the list box was destroyed.

Instead of storing references to strings in the list box, a separate string
list of directory names could be maintained and the Items.Objects array
could be used to index the directory string list.

Other Threads