Retrieve File Information (Size, Date/Time) using TDirectory.GetFiles from IOUtils in DELPHI 2010

I'm using Delphi 2010. When using FindFirst, FindNext I am aware that TSearchRec gives useful information such as: Name, Size, Date-Time, Attributes from a file.
My question is: How can I obtain the Size and Date/Time information of an archive when using TDirectory from IOUtils? For example, something as simple as this:

var
   lFiles:TStringDynArray;
   sPath:String;
   lAttributes:TFileAttributes;
   nSize: Int64;
   dFileDate: TDateTime;

begin

   lFiles := TDirectory.GetFiles( 'c:\temp\', '*.*', TSearchOption.soAllDirectories );

   // sPath contains the File Name and the complete path
   sPath := lFiles[0];

   If TFile.Exists( sPath ) then begin

      // TFile Attributes
      lAttributes := TFile.GetAttributes( sPath );

      If ( TFileAttribute.faArchive in lAttributes ) then begin

         // Now retrieve the File Size
         nSize := ???

         // Now retrieve the File Date/Time
         dFileDate := ???

     end;
   end;
end;

Open in new window

Alfredo OrtegaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
is this for 1 file or a whole list of files ?
in 1 directory or in mutliple directories ?
and in the subdirectories too ?

you already asked this question, it's the second question you ask on EE and it's basically the same

basically, what you need is a procedure which fills a List (or derived class) what info about the files on disk
with a directory and search string as a parameter

you'll have to dig in working with classes
and ... don't say you haven't worked with classes yet.
about 99% of D2010 is classes
even a Form is a class
Sinisa VukSoftware architectCommented:
Yea... duplicate question... and proposed answer is here ... Sample does not use TDirectory but this is a benefit ...
more flexible ... because you can use own file info structure - with TFileTime converted to TDatetime in place (under procedure)... but this is bit slower ....
Alfredo OrtegaAuthor Commented:
I thank you both for your answers. I don't know what you see from your side. Probably not all the information. Yes, you're right, I asked that question a fortnight ago, why repeat it? Because the first answer was useless, as the autor himself admitted he hadn't noticed I am using Delphi 2010 and he wrote something for XE7. And I received a mail 2 days ago reporting that the question was about to be deleted, I had to close it accepting the answer as a good one o rephrase the question. I did the latter. And I know it's easy for you, and imposible for those who don't know. Now I know I have to study classes, which I haven't because I've been using D7, so I am not a profesional and will never be, I use this as a pastime only. Sorry if I made you waste your time. I asked this question because I've seen many very basic questions about Delphi. Now I won't probably bother you again.
Geert GOracle dbaCommented:
hey, wasting our time is our best asset
we are bored at work/home and are looking for some real challenges and EE offers them through people like you now and then :)

it's always good to give us an idea of the level you are and what you want or need

classes is easy ... if you know record types

a class is a record, but with the added value that it can contain procedures
and you can derive a child class to add functionality on top of the parent (or change it)

to work with a class, you make an instance of the class
sample:
class: TForm1
instance: Form1

you can make multiple instances of the same class
that's a class, in a nutshell

and now back to your question
... TSearchRec, this has everything you need ? > being the size, attr and dates ?

IOUtils ... i had a quick scan of the unit
bottomline: it uses TSearchRec all over the place
so in essence, if you use TSearchRec yourself or use this unit, then you always use TSearchRec

The TDirectory.GetFiles just returns a dynamic string array with the file names
to get the file size, attributes and dates you'll have to use TFile record type

class methods of TFile
nSize := TFile.GetSize ... well that's actually missing
this thread lists, as far as i can see, all the ways on how to retrieve the file size
https://stackoverflow.com/questions/1642220/getting-size-of-a-file-in-delphi-2010-or-later
from that list, i'd use this code:
function FileSize(const aFilename: String): Int64;
  var
    info: TWin32FileAttributeData;
  begin
    result := -1;

    if NOT GetFileAttributesEx(PWideChar(aFileName), GetFileExInfoStandard, @info) then
      EXIT;

    result := Int64(info.nFileSizeLow) or Int64(info.nFileSizeHigh shl 32);
  end;

Open in new window


The dFileDate routine does exists (i'm assuming you want the last modified date)
dFileDate := TFile.GetLastWriteTime(sPath);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alfredo OrtegaAuthor Commented:
Thank you so much for your time, your kind support and your clear and useful comments. In response to your question, this is my connection with Delphi: in the mid 90s,I started writing applications for small businesses (customers, parts, invoices and accounting) in Clipper (in case you don't know, I suggest reading this: https://en.wikipedia.org/wiki/Clipper_(programming_language) ) Then I read about Delphi and I bought Delphi 2; but I only "translated" my former Clipper application into Delphi. Years later, I upgraded to Delphi 7 and, although now I'm using Delphi 2010, I've never felt the necessity of studying Delphi or programming, because I'm only an amateur. However, I've just bought an essential Delphi programming manual, because the Delphi manuals which come with the product are not so didactic as I expected / need. And in case of doubt, I rely on Neil Moffatt's Delphi Basics, available online. And yes, I understand records, now I'll start with classes, on which OOP is based.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
delphi 2010

From novice to tech pro — start learning today.