Board index » delphi » Reading contents of a directory

Reading contents of a directory

Hi Guys,

I wrote a program that synchronizes files that are in 2 different
directories. Now I'm trying to extend it so that I can synchronize
complete directories. But I've got one problem: I really don't know
how to get a list (array of string) in which is a complete directory
content saved. What could I do?

I've got another problem: Before the files are copied, they're
compared to see if it's necessary to copy them. But I wrote my own
compare-function that is very slow (via "blockread", then a "for"-loop
to compare every single bit). Is there any API I could call or a
function that uses TStream (that's very fast, I think)? The same
problem with copying files: Can I access any procedure that would
simply copy a file "a" to a file "b"?

        Thanks

                Joe

======================================================
johannes_ba...@gmx.TUDASWEG.de
To mail me, delete all underscore (_), and remove all Capslock-Letters.
======================================================

 

Re:Reading contents of a directory


Hi Guys,

I wrote a program that synchronizes files that are in 2 different
directories. Now I'm trying to extend it so that I can synchronize
complete directories. But I've got one problem: I really don't know
how to get a list (array of string) in which is a complete directory
content saved. What could I do?

I've got another problem: Before the files are copied, they're
compared to see if it's necessary to copy them. But I wrote my own
compare-function that is very slow (via "blockread", then a "for"-loop
to compare every single bit). Is there any API I could call or a
function that uses TStream (that's very fast, I think)? The same
problem with copying files: Can I access any procedure that would
simply copy a file "a" to a file "b"?

        Thanks

                Joe

======================================================
johannes_ba...@gmx.TUDASWEG.de
To mail me, delete all underscore (_), and remove all Capslock-Letters.
======================================================

Re:Reading contents of a directory


Quote
Joe wrote:
> I wrote a program that synchronizes files that are in 2 different
> directories. Now I'm trying to extend it so that I can synchronize
> complete directories. But I've got one problem: I really don't know
> how to get a list (array of string) in which is a complete directory
> content saved. What could I do?

You could try the following.

Andrew

TYPE
  FL_optionset = set of (FL_Shortnames);

{-------------------------------------------------------------
FILE_LIST    -}
{   Find all files matching Fspec, returning full names sorted in SL.
Note
    that files are ADDED to SL.}
procedure File_list (const Fspec : string; SL : Tstringlist;
        Options : FL_optionset);
var
  SR            : Tsearchrec;
  Res           : integer;
  Path          : string;
begin
  SL.Sorted := false;
  Path := extractFilePath(Fspec);
  Res := findfirst (Fspec, FA_FileOnly, SR);
  while Res = 0 do begin                {while OK}
    if (FL_Shortnames in Options)
    then SL.Add (SR.Name)
    else SL.Add (Path + SR.Name);
    Res := findnext (SR);
    end; {while}
  findclose (SR);
  SL.Sorted := true;                    {sort}
  end; {File_list}

--
Andrew Gabb
 email: ag...@tpgi.com.au
 phone: +61 8 8342-1021
   fax: +61 8 8269-3280
Technology Australasia's website is at http://www.taa.com.au
-----

Re:Reading contents of a directory


Quote
Joe wrote:
> I wrote a program that synchronizes files that are in 2 different
> directories. Now I'm trying to extend it so that I can synchronize
> complete directories. But I've got one problem: I really don't know
> how to get a list (array of string) in which is a complete directory
> content saved. What could I do?

You could try the following.

Andrew

TYPE
  FL_optionset = set of (FL_Shortnames);

{-------------------------------------------------------------
FILE_LIST    -}
{   Find all files matching Fspec, returning full names sorted in SL.
Note
    that files are ADDED to SL.}
procedure File_list (const Fspec : string; SL : Tstringlist;
        Options : FL_optionset);
var
  SR            : Tsearchrec;
  Res           : integer;
  Path          : string;
begin
  SL.Sorted := false;
  Path := extractFilePath(Fspec);
  Res := findfirst (Fspec, FA_FileOnly, SR);
  while Res = 0 do begin                {while OK}
    if (FL_Shortnames in Options)
    then SL.Add (SR.Name)
    else SL.Add (Path + SR.Name);
    Res := findnext (SR);
    end; {while}
  findclose (SR);
  SL.Sorted := true;                    {sort}
  end; {File_list}

--
Andrew Gabb
 email: ag...@tpgi.com.au
 phone: +61 8 8342-1021
   fax: +61 8 8269-3280
Technology Australasia's website is at http://www.taa.com.au
-----

Other Threads