KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In DOS batch files, the method of achieving certain things is somewhat obfuscated. Fortunately, there is a fantastic reference site for batch scripting: Simon Sheppard's SS64 . (The same site also has plenty of information about Bash .) One difficulty is branching execution based on whether a directory is empty. The obvious if exist "%dir%\*.*" doesn't work. But it can be done with this conditional execution trick: ( dir /b /a "%dir%" | findstr . ) > nul && ( echo %dir% non-empty ) || ( echo %dir% empty ) Another awkward problem is branching according to file contents. Again that can be done like this: ( fc /B "%file1%" "%file2%" | find "FC: no differences encountered" ) > nul && ( echo "%file1%" and "%file2%" are the same ) || ( echo "%file1%" and "%file2%" are different ) So, my question is: Is there a way to do branch according to the time-stamps of files? This is the sort of thing I want: REM *** pseudo-code! if "%file1%" is_newer_than "%file2%" ( echo "%file1%" is newer ) else if "%file1%" is_older_than "%file2%" ( echo "%file2%" is newer ) else ( echo "%file1%" and "%file2%" are the same age ) Thanks.
Tags (comma-separated)
Save Edits
Cancel