Check file date and replace. lazarus / 13-General ---------------------------------------------------------------------- Zath · 2016-03-01 23:53 I'm creating a small prog that acts as an updater/starter for an online game. There are 3 files that can change frequently and I want the starter to compare a client's local files and, if older/different, replace the client files with the newer/correct files. I've been looking at fileutil but only see the ability to see if a file exists and not compare. I thought "file time" might be an option and found this code from another thread here. Is it possible to use this and, if so, how ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function getcreationtime(fn:string;var v: TDateTime):Boolean;var fl:TSearchRec;begin  result:=GetFileInformation(fn,fl);  if result then    v:=filetimetodatetime(fl.FindData.ftCreationTime);end;  Long term I want to make this into an auto updater. I'm using HttpSend to retrieve files from remote server and save them locally. Any help much appreciated. ---------------------------------------------------------------------- balazsszekely · 2016-03-02 06:24 Use the following function to get the filedate as TDateTime: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses windows; function GetFileTime(const AFileName: String; var FileTime: TDateTime): Boolean;var  SR: TSearchRec;  LocalFileTime: TFileTime;  SystemTime: TSystemTime;begin  Result := False;  if FindFirst(AFileName, faAnyFile, SR) = 0 then  begin    if FileTimeToLocalFileTime(SR.FindData.ftCreationTime, LocalFileTime) then    begin      if FileTimeToSystemTime(LocalFileTime, SystemTime) then       begin         FileTime := SystemTimeToDateTime(SystemTime);         Result := True;       end;  end;    SysUtils.FindClose(SR);  end;end; procedure TForm1.Button1Click(Sender: TObject);var  FileTime: TDateTime;begin  if GetFileTime('d:\test.txt', FileTime) then    ShowMessage(FormatDateTime('YYYY.MM.DD hh:mm:ss', FileTime));end; ---------------------------------------------------------------------- Zath · 2016-03-02 17:17 Thanks for that. Something for me to work with. Just wondered why copying the code brings in the line numbers and whitespace ? ---------------------------------------------------------------------- balazsszekely · 2016-03-02 17:23 QuoteThanks for that. Something for me to work with.You're welcome! QuoteJust wondered why copying the code brings in the line numbers and whitespace ?It does not, I just test it! ---------------------------------------------------------------------- Zath · 2016-03-02 19:59 Oh yes it does ! I get it if I copy manually or use the select option. It pastes numbers onto here and directly into Laz 1.6. I'm using Win 7 and IE 11. Just tested it with Chrome too, same result. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  uses windows;  2.   3.function GetFileTime(const AFileName: String; var FileTime: TDateTime): Boolean;  4.var  5.  SR: TSearchRec;  6.  LocalFileTime: TFileTime;  7.  SystemTime: TSystemTime;  8.begin  9.  Result := False;  10.  if FindFirst(AFileName, faAnyFile, SR) = 0 then  11.  begin  12.    if FileTimeToLocalFileTime(SR.FindData.ftCreationTime, LocalFileTime) then  13.    begin  14.      if FileTimeToSystemTime(LocalFileTime, SystemTime) then  15.       begin  16.         FileTime := SystemTimeToDateTime(SystemTime);  17.         Result := True;  18.     end;  19.    end;  20.    SysUtils.FindClose(SR);  21.  end;  22.end;  23.   24.procedure TForm1.Button1Click(Sender: TObject);  25.var  26.  FileTime: TDateTime;  27.begin  28.  if GetFileTime('d:\test.txt', FileTime) then  29.    ShowMessage(FormatDateTime('YYYY.MM.DD hh:mm:ss', FileTime));  30.end; ---------------------------------------------------------------------- eny · 2016-03-02 22:35 Quote from: Zath on March 02, 2016, 08:59:37 pmOh yes it does !I recall having the same problem in the past, but not anymore. Could be Window$ (IE version) related. With Win10 the copy/paste works as expected. ---------------------------------------------------------------------- balazsszekely · 2016-03-03 06:46 @eny Yes, I was able to reproduce with the crappy IE 9.0, but who works with IE nowadays? ---------------------------------------------------------------------- Zath · 2016-03-03 09:01 Quote from: GetMem on March 03, 2016, 07:46:13 am@eny Yes, I was able to reproduce with the crappy IE 9.0, but who works with IE nowadays? I use IE 11, but, as I said in my earlier post, it also happens with Chrome. It's not much of a problem when copying a small procedure but a larger piece of code would be more difficult. ---------------------------------------------------------------------- balazsszekely · 2016-03-03 09:46 Quote@Zath I use IE 11, but, as I said in my earlier post, it also happens with Chrome. It's not much of a problem when copying a small procedure but a larger piece of code would be more difficult. Can somebody else confirm this with Chrome, Mozilla, etc..(not IE)? ---------------------------------------------------------------------- eny · 2016-03-03 16:55 Quote from: GetMem on March 03, 2016, 10:46:07 amCan somebody else confirm this with Chrome, Mozilla, etc..(not IE)?Works as expected on Win10 + Firefox. ---------------------------------------------------------------------- RAW · 2016-03-03 20:07 Hmmm, funny... Works fine with Firefox 33 (NoScript On and Off) and Akelpad and Lazarus 1.4.2....