Advertisement
npocmaka

ageCompare

May 17th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. rem --compares the age of two files
  3. rem --by Vasil "npocmaka" Arnaudov
  4.  
  5. call :isOlder     "C:\test.file1" "C:\test.file2"
  6.  
  7. goto :eof
  8.  
  9. :isOlder [%1 path to first file ; %2 path to second file]
  10.     setlocal
  11.     call :get_file_c_time  "%~1" time1
  12.     call :get_file_c_time  "%~2" time2
  13.     if "%time1%" LEQ "%time2%"  (
  14.       echo YES
  15.      ) else (
  16.       echo NO
  17.      )
  18. goto :eof
  19.  
  20. :get_file_c_time [ %1 path to file; %2 variable to assign value  ]
  21.     set file_path=%~1
  22.  
  23.     if not exist "%file_path%" echo file %1 does not exist&& exit /b 1
  24.  
  25.     if "%~2" equ "" echo need a secont parameter && exit /b 2
  26.  
  27.     setlocal enableDelayedExpansion
  28.  
  29.     for /f "skip=5 tokens=1,2,3,4,5,6 delims=/:.гчЈз " %%T in ('dir /tc "%file_path%"') do (
  30.      if "%%Y" EQU "PM" (
  31.       set /a "hour=%%W+12"
  32.      ) else (
  33.         set hour=%%W
  34.      )
  35.      set ftime=%%V%%U%%T!hour!%%Y
  36.      goto :endfor
  37.     )
  38. :endfor
  39.  
  40. endlocal & set "%~2=%ftime%"
  41. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement