The inimitable Raymond Chen of Old New Thing fame once wrote a blog post about using inappropriate tools for the job. It came to my mind the other day when I needed to do a timestamp-based conditional in a batch file. The underlying cause was rather vanilla - file H is generated from file X, so if file X was modified later than H was, the batch needs to rebuild H.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fn = WScript.Arguments(n);
return fso.FileExists(fn) ?
WScript.Quit(LastModDate(0) > LastModDate(1) ? 1 : 0);
With something like this, the batch file becomes trivial:
cscript //B later.js FileX.txt FileH.txt
if errorlevel 1 MyRebuild /from H /to X
As as added bonus, if file H doesn't exist, the script returns 1 so that it's rebuilt anyway.
This is poor man's makefile. But I didn't feel like bring a dependency on make into my process.