I create a simple c program i call newest.exe. Below is the source code.
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
// syntax: newest file1 file2
//
// if age1 = age2, prints 0 age1 age2
// if age1 < age2, prints 1 age1 age2
// if age1 > age2, prints 2 age1 age2
// where
// age1 is age of file1 is seconds.
// age2 is age of file2 is seconds.
//
// To capture the output in a DOS bat file use:
// for /f "tokens=1-3" %%i in ('%srcPath%\newest.exe %src% %des%') do (
// set newest=%%i
// set age1=%%j
// set age2=%%k
// )
int main(int argc, char **argv)
{
struct stat fileStat;
time_t now;
long age1, age2;
if(argc != 3)
{
printf("syntax: %s File1 File2\n", argv[0]);
return 1;
}
now = time(NULL);
if(stat(argv[1],&fileStat) < 0) return 1;
age1 = now - fileStat.st_mtime;
if(stat(argv[2],&fileStat) < 0) return 1;
age2 = now - fileStat.st_mtime;
if( age1 == age2 )
printf("0 %d %ld\n", age1, age2);
else if( age1 < age2 )
printf("1 %d %ld\n", age1, age2);
else
printf("2 %d %ld\n", age1, age2);
return 0;
}