Elusive

Untitled

Mar 13th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. setlocal EnableDelayedExpansion
  4.  
  5. set dirsrc=%~f1
  6. set dirdest=%~f2
  7.  
  8. echo Source: "%dirsrc%"
  9. echo Destination: "%dirdest%"
  10.  
  11. echo.
  12. echo.
  13. echo Cleaning files...
  14.  
  15. for /f "tokens=*" %%a in ('dir /s /b /a:-d "%dirdest%"') do (
  16.     set curdest=%%a
  17.     set cursrc=!curdest:%dirdest%=%dirsrc%!
  18.  
  19.     if not exist !cursrc! (
  20.         echo Deleting "!curdest!"
  21.         del "!curdest!"
  22.     )
  23. )
  24.  
  25. echo.
  26. echo.
  27. echo Cleaning directories...
  28.  
  29. set NLM=^
  30.  
  31.  
  32. set NL=^^^%NLM%%NLM%^%NLM%%NLM%
  33. rem Two lines left empty for NewLine to work
  34.  
  35. for /f "tokens=*" %%a in ('dir /s /b /a:d "%dirdest%"') do (
  36.     set curdest=%%a
  37.     set cursrc=!curdest:%dirdest%=%dirsrc%!
  38.  
  39.     if not exist !cursrc! (
  40.         set rmlist=!curdest!?!rmlist!
  41.     )
  42. )
  43.  
  44. set rmlist=!rmlist:?=%NL%!
  45.  
  46. for /f "tokens=*" %%a in ("!rmlist!") do (
  47.     if exist %%a (
  48.         echo Removing directory "%%a"
  49.         rmdir "%%a"
  50.     )
  51. )
  52.  
  53. endlocal
Advertisement
Add Comment
Please, Sign In to add comment