Forum > General
Help with tsearchrec
SteveSS:
Sorry for the delay. Yes - Windows 10, Lazarus 1.8.4. Can I ask a slightly different question ... when you hover the mouse over a .jpg image it shows (among other things) the date taken in dd/mm/yyyy hh.mm format. All I want to do is extract the date / time in lazarus code.
Steve
marcov:
And I explained to you that that date is INSIDE the jpg file, and not in the attributes parsable with findfirst/findnext.
For those you need to use fpexif or gdiplus as per https://learn.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-reading-and-writing-metadata-use
KodeZwerg:
I am still a little bit confused, so here is another way to retrieve, if stored, the times for a file.
Maybe it help to clarify what you really want to get:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Windows; procedure TForm1.Button1Click(Sender: TObject); function FileTimeToLocalSystemTime(const FileTime: TFileTime): TSystemTime; var LocalTime: TFileTime; begin try FileTimeToLocalFileTime(FileTime, LocalTime); finally FileTimeToSystemTime(LocalTime, Result); end; end; function FileTimeToDateTime(const FileTime: TFileTime): TDateTime; var SystemTime: TSystemTime; begin try SystemTime := FileTimeToLocalSystemTime(FileTime); finally with SystemTime do Result := EncodeDate(wYear, wMonth, wDay) + EncodeTime(wHour, wMinute, wSecond, wMilliseconds); end; end; function FileTimeToStr(const FileTime: TFileTime): string; var DateTime: TDateTime; begin try DateTime := FileTimeToDateTime(FileTime); finally Result := DateTimeToStr(DateTime); end; end;type TTimeStr = packed record Creation, Access, Written: string; end;var hFindFile: THandle; FindData: TWin32FindData; sPath: string; TimeStr: TTimeStr;begin if OpenDialog1.Execute then begin sPath := OpenDialog1.FileName; hFindFile := Windows.FindFirstFile(PChar(sPath), FindData); if (hFindFile <> INVALID_HANDLE_VALUE) then begin TimeStr.Creation := FileTimeToStr(FindData.ftCreationTime); TimeStr.Access := FileTimeToStr(FindData.ftLastAccessTime); TimeStr.Written := FileTimeToStr(FindData.ftLastWriteTime); Windows.FindClose(hFindFile); Memo1.Lines.BeginUpdate; Memo1.Clear; Memo1.Lines.Add('File: ' + sPath); Memo1.Lines.Add('Access: ' + TimeStr.Access); Memo1.Lines.Add('Creation: ' + TimeStr.Creation); Memo1.Lines.Add('Written: ' + TimeStr.Written); Memo1.Lines.EndUpdate; end; end;end;If your needed time is not shown up with above way, than use what marcov told.
paweld:
Example attached - use TFileSearcher and fpexif
Remy Lebeau:
--- Quote from: marcov on March 21, 2023, 02:06:53 pm ---Stranger though, SteveSS' code is not compiled by Delphi either. It doesn't know filetimetodatetime either.
--- End quote ---
There is no FileTimeToDateTime() function in Delphi, so it must have been a custom function in whatever project that code was taken from. There is a FileDateToDateTime() function in the SysUtils unit, but you can't pass SearchRec.FindData.ftLastWriteTime to it, you would have to pass in SearchRec.Time instead.
Navigation
[0] Message Index
[*] Previous page