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

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
thierryt
Posts: 47
Joined: April 26th, 2017, 12:17 pm

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

Post 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.
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

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

Post 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.
thierryt
Posts: 47
Joined: April 26th, 2017, 12:17 pm

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

Post by thierryt »

Hi Khurshid !
Thanks a lot !
Post Reply