Page 1 of 1

How to compare file dates and make a report for newer files

Posted: 24 Aug 2012 00:09
by avsfan
Hi,

I've got a situation where I've got a bunch of files, each of which gets processed by different applications resulting in multiple different output files for each input file. For example, if my input files are file-1, file-2 and file-3, after all processing is complete I'll have file-1-urf, file-1-ack, and file-1-spam (and similarly for file-2 and file-3).

What I'm looking to do is to make a script that will compare the modified date of the input files with either the modified or created date of the associated output files, and let me know, for each input file, which of the output files are older (i.e. which ones need to be processed).

I've done some other basic scripting, but nothing related to this -- any pointers or ideas will be much appreciated!

Thanks!

andy

Re: How to compare file dates and make a report for newer fi

Posted: 24 Aug 2012 08:21
by admin
I will add date compare to SC compare(), that will help a little.

Re: How to compare file dates and make a report for newer fi

Posted: 24 Aug 2012 08:24
by highend
One way to do that:

create a new tab (clones the current)
filter the current list (an exclude filter that hides the three extensions, that are created) | or a filter that selects all source files automatically (by e.g. extension)
a variable, that contains all of your three extensions
iterate (foreach) over this variable, combined with the basename of the appropriate source file)
and in the loop create a list via datediff between the destination and the source file(s).
I'd suggest seconds for datediff and you only have to check if they're != 0 (because >=1 means, dst file is older).

At least that's how I'd solve it.

Re: How to compare file dates and make a report for newer fi

Posted: 24 Aug 2012 09:09
by avsfan
Thanks for the initial thoughts. One thing I forgot to mention in the first post that makes it *slightly* more complicated -- the files generated are in a subdirectory below the initial files.

One thing that should make it easier is that the names of the initial files don't change -- it's a fixed set of files, so that list could actually just be a static list without needing to worry about selection, etc.
ugly pseudo-code might look something like this :

Code: Select all

for each file in (myfile-1.src, myfile-2.src, myfile-3.src, myfile-4.src)
  for each suffix in (-urf.dll, -ack.dll, -spam.dll)
    if date_modified(file) > date_created(basename(file).suffix)  then
      add file to needs_update list
    else
      add file to OK list
    end_if
  end 
end

[report code come next]
Is this more clear?

Thanks!

Re: How to compare file dates and make a report for newer fi

Posted: 24 Aug 2012 09:46
by highend
the files generated are in a subdirectory below the initial files.
You have to build the file paths in the second foreach loop anyway so it doesn't make such a difference. You just have to append the subdir name to the <curpath>.
it's a fixed set of files, so that list could actually just be a static list without needing to worry about selection
So you can either use just one string with "|" as a separator or (for better readability) the heredoc syntax depending on
how many files you to process.
ugly pseudo-code might look something like this :
Doesn't look bad.

Re: How to compare file dates and make a report for newer fi

Posted: 25 Aug 2012 00:16
by avsfan
highend wrote:
it's a fixed set of files, so that list could actually just be a static list without needing to worry about selection
So you can either use just one string with "|" as a separator or (for better readability) the heredoc syntax depending on
how many files you to process.
ugly pseudo-code might look something like this :
Doesn't look bad.
Now my real question is how to convert it into something that will actually work... Help, please!

Thanks in advance!

andy

Re: How to compare file dates and make a report for newer fi

Posted: 25 Aug 2012 01:42
by highend

Code: Select all

$srcFiles=<<<>>>
D:\Temp\test\abc.src
D:\Temp\test\def.src
D:\Temp\test\geh.src
>>>;

	$subFolderName = "processed";
	$dstExtensions = "-urf.dll|-ack.dll|-spam.dll";

	// Main part
	$changedFileList = "";
	foreach($file, $srcFiles, "<crlf>") {
		$modifiedSourceDate = property("Write", $file);
		$processedPath = regexreplace($file, "(.*\\).*", "$1$subFolderName\" . getpathcomponent($file, "base"));
		foreach($item, $dstExtensions, "|") {
			$processedItem = $processedPath . $item;
			if(exists($processedItem) == 1) {
				$modifiedDstDate = property("Write", $processedItem);
				if(datediff($modifiedSourceDate, $modifiedDstDate, "n") < 0) {
					$changedFileList = $changedFileList . $processedItem . "<crlf>";
				}
			}
		}
	}
	text $changedFileList;
Compares the modified time of the three other files (if they exist) with the modified time of the corresponding source file. If they are older, they make their way into the list.

Tested it a few times, looks ok so far.

Re: How to compare file dates and make a report for newer fi

Posted: 25 Aug 2012 23:09
by avsfan
Excellent! Thanks very much!