Guest User

Untitled

a guest
May 17th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.06 KB | None | 0 0
  1. @echo off
  2. del /S *.json
  3. for /f "tokens=*" %%f in ('dir /a:-D /s /b') do call :SUB_COPY "%%f" "I:\"
  4. for /f "tokens=*" %%f in ('dir /a:D /s /b') do rd "%%f"
  5. exit /B
  6.  
  7.  
  8. :SUB_COPY source_item target_dir
  9. if not "%~3"=="" (
  10.     >&2 echo ERROR: too many arguments!
  11. )
  12. set "SOURCE=%~f1"
  13. if not defined SOURCE (
  14.     >&2 echo ERROR: missing argument!
  15.     exit /B 1
  16. ) else if not exist "%SOURCE%" (
  17.     >&2 echo ERROR: source not found!
  18.     exit /B 1
  19. )
  20. set "TARGET=%~f2"
  21. if not defined TARGET set "TARGET=."
  22.  
  23. for /F "delims=" %%I in ('
  24.     2^> nul xcopy /L /S /E /Y /I "%SOURCE%" "%TEMP%\" ^| findstr /V /R "^[0-9]"
  25. ') do (
  26.     > con echo "%%~I"
  27.     call :SUB_DO "%%~I" "%TARGET%"
  28. )
  29. exit /B
  30.  
  31. :SUB_DO source_file target_dir
  32. set "SUFFIX="
  33. :CHECK
  34. if exist "%~f2\%~n1%SUFFIX%%~x1" (
  35.     set /A SUFFIX-=1
  36. ) else (
  37.     2> nul md "%~f2"
  38.     > nul 2>&1 copy /B "%~f1" "%~f2\%~n1%SUFFIX%%~x1" && (
  39.         echo INFO: copied "%~nx1" as "%~n1%SUFFIX%%~x1".
  40.     ) || (
  41.         >&2 echo ERROR: copying of "%~nx1" failed!
  42.         exit /B 1
  43.     )
  44.     exit /B
  45. )
  46. goto :CHECK
Advertisement
Add Comment
Please, Sign In to add comment