Link to home
Start Free TrialLog in
Avatar of 4Rabbits
4Rabbits

asked on

Whats the best way of getting the 3 Date & Time Files of a File.

Hi Experts!?

I'd Like to know your opinions on the best, shortest & quickest route to display all the Date & Times.

The 3 Dates & Times am after are Created, Modified & Accessed.


I'd be calling them calling from a Function, which is like..
memo1.lines.add('Created: '+GetDate(file, 1, long));
1=Created
2=Modified
3=Accessed
4=Created & Modified
ect..

should I use Case or If for that function?

but getting back to the Date & Time of the file.

I'd like to be able to display them in there true long format and short format.

long = Tuesday, February 14, 2006, 09:50:19
short = 14/02/06 09:50:19


Thanks
4R.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany 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
Avatar of AmigoJack
AmigoJack

function getDateTimeString(ft1: filetime; iDateType: DWORD= 0): string;
var
  st1: systemtime;
  s1: string;
  p1: pchar;
begin
  getmem(p1, 300);

  filetimetolocalfiletime(elem^.tTime, ft1);
  filetimetosystemtime(ft1, st1);
  getdateformat(LOCALE_USER_DEFAULT, iDateType, @st1, nil, p1, 300);
  s1:= strpas(p1)+ ' ';
  gettimeformat(LOCALE_USER_DEFAULT, 0, @st1, nil, p1, 300);
  s1:= s1+ strpas(p1);
  item.SubItems.Add(s1);

  freemem(p1);
  result:= s1;
end;

procedure listFileTimes(fname: string; DWORD iDateType= 0);
var
  wfd: win32_find_data;
  h1: thandle;
begin
  h1:= findfirstfile(pchar(fname), wfd);
  if h1= INVALID_HANDLE_VALUE then exit;

  with form1.memo1.lines do begin
    add('last write: '+ getDateTimeString(wfd.ftLastWriteTime, iDateType));
    add('created: '+ getDateTimeString(wfd.ftCreationTime, iDateType));
    add('last access: '+ getDateTimeString(wfd.ftLastAccessTime, iDateType));
  end;
  windows.findclose(h1);
end;




you should try the example with a memo1 on your form. call it like this

  listFileTimes('c:\boot.ini', DATE_LONGDATE);
  listFileTimes('c:\boot.ini', DATE_SHORTDATE);

havent tested it, but i know GetDateFormat() is working for giving the date in any format you like. plus FindFirstFile() gives you more rapid all file times. if you have any further questions dont bother :)
SOLUTION
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
Avatar of 4Rabbits

ASKER

Thanks meikl.

AmigoJack, for some reason I couldn't get it to work :(

errors here #error#

 filetimetolocalfiletime(#elem^#.tTime, ft1);

thanks.
4R.
whoops - exactly that line: delete it :)