Board index » delphi » How to get listing of files in a directory using Delphi 3.0

How to get listing of files in a directory using Delphi 3.0

Hello,

I am looking for a technique to access a listing of files in a
particular directory using the standard Delphi components that come
with v3.0.  I am fairly new to Windows programming, but I have written
several apps that need to process all files in a particular directory.
What I have been doing to accomplish this task is to spawn COMMAND.COM
for a piped-DIRECTORY listing which I have another routine process to
get each filename.  I know there has to be an easier way, but I
haven't had any luck using any of the file window controls that come
with Delphi.

If anyone can shed any light on this subject, I would appreciate it
greatly.  Thanks!

        -Lee

 

Re:How to get listing of files in a directory using Delphi 3.0


Quote
Green Cubex wrote:

> Hello,

> I am looking for a technique to access a listing of files in a
> particular directory using the standard Delphi components that come
> with v3.0.  I am fairly new to Windows programming, but I have written
> several apps that need to process all files in a particular directory.
> What I have been doing to accomplish this task is to spawn COMMAND.COM
> for a piped-DIRECTORY listing which I have another routine process to
> get each filename.  I know there has to be an easier way, but I
> haven't had any luck using any of the file window controls that come
> with Delphi.

> If anyone can shed any light on this subject, I would appreciate it
> greatly.  Thanks!

>         -Lee

You could use the FindFirst and FindNext functions. To retrieve the file
info.

Re:How to get listing of files in a directory using Delphi 3.0


Use the FindFirst and FindNext functions to read the directory one entry
at a time.

Re:How to get listing of files in a directory using Delphi 3.0


Quote
TL Stephan (tstep...@nanaimo.ark.com) wrote:
: Green Cubex wrote:

: >
: > Hello,
: >
: > I am looking for a technique to access a listing of files in a
: > particular directory using the standard Delphi components that come
: > with v3.0.  I am fairly new to Windows programming, but I have written
: > several apps that need to process all files in a particular directory.
: > What I have been doing to accomplish this task is to spawn COMMAND.COM
: > for a piped-DIRECTORY listing which I have another routine process to
: > get each filename.  I know there has to be an easier way, but I
: > haven't had any luck using any of the file window controls that come
: > with Delphi.
: >
: > If anyone can shed any light on this subject, I would appreciate it
: > greatly.  Thanks!
: >
: >         -Lee
:
: You could use the FindFirst and FindNext functions. To retrieve the file
: info.

Hi,
        I quick way is to use the TFileListBox component. A sample code
is given below:

        procedure FilesInDirectory(Dir: string, FileList: TStringList);
        var
          FileListBox: TFileListBox;
        begin
          FileListBox := TFileListBox.Create(Self);
          try
            FileListBox.Directory := Dir;
            FileList.Assign(FileListBox.Items)
          finally
            FileListBox.Free
          end
        end;

To use this routine use a code like this:

        var
          FileList: TStringList;
        begin
          FileList := TStringList.Create;
          try
            FilesInDirectory('\', FileList);
            ...
            ...
            ...
          finally
            FileList.Free
          end
        end;

HTH.

                                      - Chirag Dalal

----------------------------------------------------------
 M. Tech., Department of Computer Science and Engineering
 Indian Institute of Technology, Powai, Bombay.
----------------------------------------------------------
 E-Mail Address: da...@cse.iitb.ernet.in

 For Cool Delphi Components See
 Home page: http://www.cse.iitb.ernet.in/~dalal/delphi
----------------------------------------------------------

Other Threads