Link to home
Start Free TrialLog in
Avatar of Alfredo Ortega
Alfredo Ortega

asked on

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

Avatar of Geert G
Geert G
Flag of Belgium image

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
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 ....
Avatar of Alfredo Ortega
Alfredo Ortega

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.