Page 1 of 1

how return the date of modification of a file in the logic

Posted: June 7th, 2018, 6:14 pm
by thierryt
Hi all,
please i want to know if there is a function who return the date of the modification of a file, like :
Date("C:\test.dat") returns 07/06/2018.
or how can i do if i want to use in logic the last date of modification of a file ?
i want to compare two versions of a file in differents folders and just take the most recent.
Thanks.

Re: how return the date of modification of a file in the logic

Posted: June 8th, 2018, 3:30 am
by khurshid.arshad
Dear

Maybe You can use log file to get the last date of modification or addition and I hope it works for you or josh and Gregory give you a better solution.

The syntax for 7.1.2 is as follows:

Code: Select all

File 		Datefile;
String	PreLoad_Data; 

	numeric i = setfile (Datelog, "..\Data\firstfile.csdb.log");//set first file

	while fileread (Datelog, PreLoad_Data) do; //run loop to read file till end
					string firstfiledate=PreLoad_Data[38:10]; //38: is starting point in log file
													//10: is number of digits 
													//These information you can get from the help file "LOG" 
		enddo;
	
	close(Datelog);	//Close first log file


	i = setfile (Datelog, "..\Data\secondfile.csdb.log");//  set second file
	
	while fileread (Datelog, PreLoad_Data) do;
					string secondfiledate=PreLoad_Data[38:10];
		enddo;
		
	close(Datelog);
	
	
	if firstfiledate=secondfiledate then
		errmsg ("Use first file");
	else
		errmsg ("Use second file");
	endif;

But in your case you need time as well because if there is no change in date but change in time. In this case you will use the range:

Code: Select all

	string firstfiledate=PreLoad_Data[38:19];
	string secondfiledate=PreLoad_Data[38:19];

Best.
a.

Re: how return the date of modification of a file in the logic

Posted: June 11th, 2018, 6:24 am
by thierryt
Hi Khurshid !
Thanks a lot !