daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. setlocal EnableExtensions DisableDelayedExpansion
  3.  
  4. rem // Define constants here:
  5. set "_ROOT=%~dp0." & rem // (common root directory; `%~dp0.` is script's parent, `.` is current)
  6. set "_DIR1=%_ROOT%Directory1" & rem // (1st directory containing files)
  7. set "_DIR2=%_ROOT%Directory2" & rem // (2nd directory containing files)
  8. set _MASKS="*INV*." "*SLS*."     & rem // (list of quoted file masks)
  9. set "_TMP1=%TEMP%%~n0_1_%RANDOM%.tmp" & rem // (1st temporary file)
  10. set "_TMP2=%TEMP%%~n0_2_%RANDOM%.tmp" & rem // (2nd temporary file)
  11.  
  12. rem // Resolve 1st directory to be an absolute path:
  13. for %%E in ("%_DIR1%") do set "RDIR1=%%~fE"
  14. rem // Resolve 2nd directory to be an absolute path:
  15. for %%E in ("%_DIR2%") do set "RDIR2=%%~fE"
  16.  
  17. rem // Write all matching files in 1st directory to 1st temporary file:
  18. pushd "%RDIR1%" && (
  19.     for %%F in (%_MASKS%) do (
  20.         echo(%%~nxF
  21.     )
  22.     popd
  23. ) > "%_TMP1%"
  24. rem // Write all matching files in 2nd directory to 2nd temporary file:
  25. pushd "%RDIR2%" && (
  26.     for %%F in (%_MASKS%) do (
  27.         echo(%%~nxF
  28.     )
  29.     popd
  30. ) > "%_TMP2%"
  31.  
  32. rem // Loop over all common files from both temporary files:
  33. for /F %%L in ('findstr /L /I /X /G:"%_TMP1%" "%_TMP2%"') do (
  34.     rem // Build absolute `wmic`-compatible file paths:
  35.     set "FILE1=%RDIR1:=\%\%%L" & set "FILE2=%RDIR2:=\%\%%L"
  36.     setlocal EnableDelayedExpansion
  37.     rem set "FILE1=%!FILE1:&=&!" & set "FILE2=%!FILE2:&=&!"
  38.     rem // Get standardised file date/time (last modification) of 1st file by `wmic`:
  39.     for /F %%K in ('wmic DataFile where "Name='!FILE1!'" get LastModified') do set "DATE1=%%K"
  40.     rem // Get standardised file date/time (last modification) of 2nd file by `wmic`:
  41.     for /F %%K in ('wmic DataFile where "Name='!FILE2!'" get LastModified') do set "DATE2=%%K"
  42.     rem // Compare file dates/times (last mod.) of both files and return differing ones:
  43.  @echo on
  44. if !DATE1! gtr !DATE2! echo "!FILE1:\=!" is newer than "!FILE2:\=!"
  45. if !DATE1! lss !DATE2! echo "!FILE1:\=!" is older than "!FILE2:\=!"
  46. if !DATE1! equ !DATE2! echo "!FILE1:\=!" is same with  "!FILE2:\=!"
  47.  
  48.     endlocal
  49. )
  50.  
  51. rem // Clean up temporary files:
  52. del "%_TMP1%" "%_TMP2%"
  53.  
  54. endlocal
  55. exit /B
  56.      
  57. Microsoft Windows [Version 6.1.7601]
  58. Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
  59.  
  60. C:Usersksaycon>cd Desktop
  61.  
  62. C:UsersksayconDesktop>sample.bat
  63. "C:UsersksayconDesktopDirectory1FFPDFINV06" is same with  "C:Usersksaycon
  64. DesktopDirectory2FFPDFINV06"
  65.  
  66. C:UsersksayconDesktop>(
  67. rem // Build absolute `wmic`-compatible file paths:
  68.  set "FILE1=C:\Users\ksaycon\Desktop\Directory1\FFPDFSLS02"   & set "FILE2=
  69. C:\Users\ksaycon\Desktop\Directory2\FFPDFSLS02"
  70.  setlocal EnableDelayedExpansion
  71.  rem set "FILE1=&=&!" & set "FILE2=&=&!"
  72.  rem // Get standardised file date/time (last modification) of 1st file by `wmic
  73. `:
  74.  for /F %K in ('wmic DataFile where "Name='!FILE1!'" get LastModified') do set "
  75. DATE1=%K"
  76.  rem // Get standardised file date/time (last modification) of 2nd file by `wmic
  77. `:
  78.  for /F %K in ('wmic DataFile where "Name='!FILE2!'" get LastModified') do set "
  79. DATE2=%K"
  80.  rem // Compare file dates/times (last mod.) of both files and return differing
  81. ones:
  82.  
  83.  if !DATE1! GTR !DATE2! echo "!FILE1:\=!" is newer than "!FILE2:\=!"
  84.  if !DATE1! LSS !DATE2! echo "!FILE1:\=!" is older than "!FILE2:\=!"
  85.  if !DATE1! EQU !DATE2! echo "!FILE1:\=!" is same with  "!FILE2:\=!"
  86.  endlocal
  87. )
  88.  
  89. C:UsersksayconDesktop>set "DATE1=LastModified"
  90.  
  91. C:UsersksayconDesktop>set "DATE1=20190318040549.218407+480"
  92.  
  93. " UsersksayconDesktop>set "DATE1=
  94.  
  95. C:UsersksayconDesktop>set "DATE2=LastModified"
  96.  
  97. C:UsersksayconDesktop>set "DATE2=20190318095134.760320+480"
  98.  
  99. " UsersksayconDesktop>set "DATE2=
  100. "C:UsersksayconDesktopDirectory1FFPDFSLS02" is same with  "C:Usersksaycon
  101. DesktopDirectory2FFPDFSLS02"
  102.  
  103. C:UsersksayconDesktop>rem // Clean up temporary files:
  104.  
  105. C:UsersksayconDesktop>del "C:UsersksayconAppDataLocalTempsample_1_13650
  106. .tmp" "C:UsersksayconAppDataLocalTempsample_2_27021.tmp"
  107.  
  108. C:UsersksayconDesktop>endlocal
  109.  
  110. C:UsersksayconDesktop>exit /B
  111.  
  112. C:UsersksayconDesktop>^A
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top