1iJaCk

cbzme.bat

May 4th, 2017
243
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.37 KB | None | 0 0
  1. ::
  2. :: JK'D Blame-Game Agreement 1.0a, "Finger-Pointer Edition", written by JaCk
  3. ::
  4. ::: No Warranty, No Guarantee, No Support, AS-IS
  5. :::
  6. ::: USE AT YOUR OWN RISK
  7. ::: By sheer discretion and without notification, JaCk, retains the all rights, including exemptions, revocation of exemptions of this agreement!
  8. :::
  9. ::: By Running this script or ANY portion of it's, this script's, contents, you agree to the following:
  10. ::: - that you fully understand what these commands, expressions, functions, and/or script(s) or portions of script(s) do
  11. ::: - that you take responsibility for any actions, damages, physical losses, intellectual property losses, and/or losses of ANY kind
  12. ::: - that you DO NOT seek compensation of any kind, monies or otherwise, in ANY FORM, from previous, current and future parties; not limited to:
  13. :::    -- anyone
  14. :::    -- everyone
  15. :::    -- it's author(s)
  16. :::    -- it's contributor(s)
  17. :::    -- any beneficiaries
  18. :::    -- users
  19. :::    -- distributors
  20. ::
  21. :::::::::::::::::::::::::::::::::::::::
  22.  
  23. :: By JaCk | Release 05/04/2017 | https://pastebin.com/6vEQscEX | cbzme.bat  - Creates cbz files using the 7-zip binary
  24. @echo off & setlocal EnableDelayedExpansion
  25.  
  26. :: This script is based on http://alanhorkan.livejournal.com/58404.html
  27. ::  - which was based on http://aarmstrong.org/tutorials/mass-zip-rar-to-7zip-recompression-batch-file
  28. ::  -- "Mass Zip, RAR to 7Zip Recompression Batch File by Andrew Armstrong"
  29. ::
  30. ::
  31. :: Recurses through a directory and creates cbz [Comic Book Zip] files using 7z
  32. ::
  33. :: Directory Structure for the input
  34. :: - C:\cbme_plox\source\Comic 123\000.jpg
  35. :: ---- [C:\cbme_plox\source] is the base directory for [cbzme_var_source_directory]
  36. :: ---- Note: [Comic 123] is the title of name of the Book.  This name will be used for the new cbz file like: [Comic 123.cbz]
  37. :: ---- Note: [000.jpg] is one of the images in [Comic 123]
  38.  
  39.  
  40. :::::::::::::::::::::::::::::::::::::::
  41. ::
  42. :: User Variables (Settings)
  43. ::
  44. :::::::::::::::::::::::::::::::::::::::
  45. set "cbzme_var_7z_bin_full_path=%ProgramFiles%\7-Zip\7z.exe"       rem Default: [Binary Location] - This is the full path to the 7-zip binary.  http://www.7-zip.org
  46. set "cbzme_var_source_directory="                                  rem Default: [NotSet]          - This is the full path to the source directory contains the sub-directories that you would like processed.  If not set, script will ask user for input.
  47. set "cbzme_var_output_directory="                                  rem Default: [NotSet]          - This is the full path to the output directory with future cbz output files (if all the stars align).  If not set, script will ask user for input.
  48.  
  49.  
  50. :::::::::::::::::::::::::::::::::::::::::::
  51. :::::::::::::::::::::::::::::::::::::::::::
  52. :::: Unless you know what you're doing ::::
  53. :::: DO NOT CHANGE BELOW               ::::
  54. :::::::::::::::::::::::::::::::::::::::::::
  55. :::::::::::::::::::::::::::::::::::::::::::
  56.  
  57. :::::::::::::::::::::::::::::::::::::::
  58. ::
  59. :: Prompts
  60. ::
  61. :::::::::::::::::::::::::::::::::::::::
  62.  
  63. if not defined cbzme_var_7z_bin_full_path (
  64.    rem Try to locate the bin in the PATH system variable and set it as the default
  65.    rem If multiple are located, script will always choose the last one on the list
  66.     for /f "tokens=* delims=" %%s in ('where 7z.exe') do set "cbzme__input=%%~s"
  67.  
  68.     rem Ask user for input
  69.     echo/
  70.     echo INPUT: 7z: Please Enter the full directory path for the 7z.exe binary:
  71.     echo INPUT: 7z: Default: [!cbzme__input!]
  72.     set /p "cbzme__input=: "
  73.    
  74.     set "cbzme_var_7z_bin_full_path=!cbzme__input!"
  75.     echo/
  76. )
  77.  
  78. if not defined cbzme_var_source_directory (
  79.     set "cbzme__input=%~dp0"
  80.  
  81.     echo/
  82.     echo INPUT: Source: Please Enter the full INPUT directory path containing the sub-directories to be processed.
  83.     echo INPUT: Source: Default: [!cbzme__input!]
  84.     set /p "cbzme__input=: "
  85.    
  86.     set "cbzme_var_source_directory=!cbzme__input!"
  87.     echo/
  88. )
  89.  
  90. if not defined cbzme_var_output_directory (
  91.     set "cbzme__input=%~dp0\output"
  92.  
  93.     echo/
  94.     echo INPUT: Output: Please Enter the full directory OUTPUT path for the new cbz files
  95.     echo INPUT: Output: Default: [!cbzme__input!]
  96.     set /p "cbzme__input=: "
  97.    
  98.     set "cbzme_var_output_directory=!cbzme__input!"
  99.     echo/
  100. )
  101.  
  102. :: I need cleansing
  103. :: - forgive me father for I have been used, multiple times on multiple occasions and as a temporary placeholder...
  104. set "cbzme__input="
  105.  
  106.  
  107. :::::::::::::::::::::::::::::::::::::::
  108. ::
  109. :: Basic Error Checking
  110. ::
  111. :::::::::::::::::::::::::::::::::::::::
  112. set "cbzme__debug_flag="
  113. set "cbzme__fatal_flag=0"
  114. set "cbzme__error_count=0"
  115.  
  116. if not exist "%cbzme_var_7z_bin_full_path%" (
  117.     echo/
  118.     echo ERROR: FATAL: 7zBin: Unable to access or find [%cbzme_var_7z_bin_full_pathr%]
  119.     echo/
  120.     set /a "cbzme__fatal_flag+=1"
  121. )
  122.  
  123.  
  124. if not exist "%cbzme_var_source_directory%" (
  125.     echo/
  126.     echo ERROR: FATAL: Source Dir: Unable to access or find [%cbzme_var_source_directory%]
  127.     echo/
  128.     set /a "cbzme__fatal_flag+=1"
  129. )
  130.  
  131.  
  132. if !cbzme__fatal_flag! gtr 0 (
  133.     echo/
  134.     echo ERROR: FATAL: Encountered Fatals - [!cbzme__fatal_flag!]
  135.     echo INFO: Exiting...
  136.     echo/
  137.     timeout /t 15
  138.     exit /b 1
  139. )
  140.  
  141.  
  142. if not exist "%cbzme_var_output_directory%" (
  143.     echo/
  144.     echo/ INFO: Output Dir: directory does not exist, Creating...
  145.     mkdir "%cbzme_var_output_directory%" || (
  146.         echo/
  147.         echo ERROR: Output Dir: Unable to create path [%cbzme_var_output_directory%]
  148.         echo INFO: Continuing...
  149.         echo/
  150.     )
  151.     echo/
  152. )
  153.  
  154.  
  155.  
  156. :::::::::::::::::::::::::::::::::::::::
  157. ::
  158. :: Main
  159. ::
  160. :::::::::::::::::::::::::::::::::::::::
  161.  
  162. rem Setting default string before all the magic
  163. set "cbzme__d=!date:* =!" & set "cbzme__t=!time:~0,-3!"
  164. set "cbzme__time_string=!cbzme__d:/=.!-!cbzme__t::=.!"
  165. set "cbzme__time_string=!cbzme__time_string: =!"
  166.  
  167. :: Grab a quick total count
  168. set "cbzme__dtcount=0"
  169. for /f "tokens=1* delims=" %%d in ('
  170.         dir /b /o:-n /a:d "!cbzme_var_source_directory!"
  171. ') do set /a "cbzme__dtcount+=1"
  172.  
  173.  
  174. :: Give a pretty message or exit script
  175. if !cbzme__dtcount! gtr 0 (
  176.     echo: INFO: CBZ: Total Directories to Process [!cbzme__dtcount!]
  177.     echo/
  178. ) else (
  179.     echo ERROR: FATAL: No Directories found to process in [!cbzme_var_source_directory!]
  180.     echo/
  181.     exit /b 1
  182. )
  183.  
  184.  
  185. :: Recurse through source directory and create cbz files in the output directory
  186. :: files named [z*.*] and [Thumbs.db] will automaticlly be ignored and NOT added into the new cbz file
  187. set "cbzme__dpcount=0"
  188. for /f "tokens=1* delims=" %%d in ('
  189.         dir /b /o:-n /a:d "!cbzme_var_source_directory!"
  190. ') do (
  191.    rem Assign me to my var plx
  192.         set /a "cbzme__dpcount+=1"
  193.         set "cbzme__dname=%%~d"
  194.    
  195.     rem set the title and print message to console
  196.         title %~0: Processing [!cbzme__dpcount!/!cbzme__dtcount!] - !cbzme__dname!.cbz
  197.         echo/
  198.         echo/ ========================================
  199.         echo/
  200.         echo INFO: CBZ: Processing [!cbzme__dpcount!/!cbzme__dtcount!] - !cbzme__dname!.cbz
  201.    
  202.     rem call the binary with all the parameters
  203.         if defined cbzme__debug_flag echo call "!cbzme_var_7z_bin_full_path!" a -tzip "%cbzme_var_output_directory%\%%~d.cbz" -mx=0 '-x^^!Thumbs.db*' "%cbzme_var_source_directory%\%%~d"
  204.         2>>"%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log" call "!cbzme_var_7z_bin_full_path!" a -tzip "%cbzme_var_output_directory%\%%~d.cbz" -mx=0 '-x^^!Thumbs.db*' "%cbzme_var_source_directory%\%%~d"
  205.        rem call "!cbzme_var_7z_bin_full_path!" a -tzip "%cbzme_var_output_directory%\%%~d.cbz" -mx=0 '-x^^!Thumbs.db*' '-x^^!z*.*' "%cbzme_var_source_directory%\%%~d"
  206.  
  207.     rem check if bin exited cleanly
  208.         if !errorlevel! neq 0 (
  209.             echo ERROR: CBZ: 7ZBin: Encountered unknown errors or warnings while creating [!cbzme_var_output_directory!\!cbzme__dname!.cbz]
  210.             echo ERROR: CBZ: 7ZBin: Encountered unknown errors or warnings while creating [!cbzme_var_output_directory!\!cbzme__dname!.cbz] >> "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log"
  211.             echo/
  212.             set /a "cbzme__error_count+=1"
  213.             if defined cbzme__debug_flag timeout /t 3
  214.         )
  215.         echo/
  216.         echo/ ========================================
  217.         echo/
  218.    rem if defined cbzme__debug_flag exit /b
  219. )
  220. echo/
  221.  
  222. :: Checking if the error log contains anything, if not, then we delete it
  223. type "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log" 2>nul | findstr /c:" " 2>nul 1>nul || (
  224.     del /q "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log"
  225. )
  226.  
  227. :::::::::::::::::::::::::::::::::::::::
  228. ::
  229. :: Fin-laund
  230. ::       git-it... FIN... LAUND... HAHA
  231. ::        not funny, alt-f4 yourself...
  232. ::
  233. :::::::::::::::::::::::::::::::::::::::
  234.  
  235.  
  236. if !cbzme__error_count! gtr 0 (
  237.     echo ERROR: WARNING: CBZ: 7z encountered [!cbzme__error_count!] errors or warnings
  238.     echo ERROR: WARNING: CBZ: Please Check "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log" for details
  239.     echo/
  240.    rem Gotta clean after me-self and the kitchen-sync [-.*]
  241.     for /f "tokens=* delims=" %%v in ('set cbzme_') do set "%%v="
  242.     timeout /t 30 & exit /b 1
  243. ) else (
  244.    rem Gotta clean after me-self and the kitchen-sync [-.*]
  245.     for /f "tokens=* delims=" %%v in ('set cbzme_') do set "%%v="
  246.     timeout /t 30 & exit /b 0
  247. )
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment