Advertisement
npocmaka

ProgressCopy.bat

Jul 15th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.30 KB | None | 0 0
  1. @echo off
  2. rem :: Copying files with progress bar using Esentutl
  3. rem :: by Vasil "npocmaka" Arnaudov
  4.  
  5. rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  6.  
  7. rem Esentutl is a command that performs some operations over a special windows database files (e.g. restore point files)
  8. rem From Windows Vista and above it supports copy operation which has a progress bar and can be used on ordinary files:
  9.  
  10. rem esentutl /y "FILE.EXT" /d"DEST.EXT" /o
  11. rem May be it is not completely reliable:
  12.  
  13. rem If performed on arbitrary files, this operation may fail
  14. rem at the end of the file if its size is not sector-aligned.
  15.  
  16. rem ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  17.  
  18. :progressCopy
  19. setlocal
  20. echo.
  21. for /f "skip=2 tokens=2,3 delims=. " %%V in ('esentutl /d#') do (
  22.     echo esentutl version %%V.%%W
  23.     set /a "version=%%V%%W"
  24.     goto :break
  25. )
  26. :break
  27. color
  28. if defined version if %version%0 LSS 600 (
  29.     echo UNSUPORTED VERSION
  30.     echo Lower than 6.0
  31.     exit /b 3
  32. )
  33.  
  34.  
  35. for %%H in ("/h" "-h" "-help" "/help") do (
  36.     if /I "%~1" EQU "%%~H" goto :help
  37. )
  38.  
  39. if "%~1" EQU "" (
  40.     goto :help
  41. )
  42. set "source=%~1"
  43.  
  44. if not exist "%source%" (
  45.     (echo()
  46.     echo source file does not exist
  47.     exit /b 2
  48. )
  49.  
  50. for %%F in ("/f" "/force") do (
  51.     if /I "%~3" EQU "%%~F" set "force=1"
  52.     if /I "%~2" EQU "%%~F" set "force=1" && set "dest=%~nx1"
  53. )
  54.  
  55. if "%~2" NEQ ""  (
  56.  if not defined dest set "dest=%~2"
  57. ) else (
  58.  if not defined dest set "dest=%~nx1"
  59. )
  60.  
  61. if exist "%dest%" if not defined force (
  62.     (echo()
  63.     echo file already exist and force option is not set
  64.     echo exit /b 1
  65. )
  66.  
  67. if exist "%dest%" if defined force (
  68.     (echo()
  69.     echo file already exist and will be overwritten
  70.     del /Q /F "%dest%"
  71. )
  72.  
  73. esentutl /y"%source%" /d"%dest%" /o
  74. endlocal
  75. goto :eof
  76.  
  77. :help
  78. echo.
  79. echo Copying a file with a progress bar
  80. echo.
  81. echo.
  82. echo %~nx0  source [destination] [/force^|/f]
  83. echo.
  84. echo.
  85. echo source           - path to the source file
  86. echo.
  87. echo destination      - path to the destination file.If not
  88. echo                    defined it will be set to the current directory.
  89. echo.
  90. echo /force           - overwrite the source file if exists
  91. echo.
  92. echo  by Vasil "npocmaka" Arnaudov
  93. echo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement