Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::
- :: JK'D Blame-Game Agreement 1.0a, "Finger-Pointer Edition", written by JaCk
- ::
- ::: No Warranty, No Guarantee, No Support, AS-IS
- :::
- ::: USE AT YOUR OWN RISK
- ::: By sheer discretion and without notification, JaCk, retains the all rights, including exemptions, revocation of exemptions of this agreement!
- :::
- ::: By Running this script or ANY portion of it's, this script's, contents, you agree to the following:
- ::: - that you fully understand what these commands, expressions, functions, and/or script(s) or portions of script(s) do
- ::: - that you take responsibility for any actions, damages, physical losses, intellectual property losses, and/or losses of ANY kind
- ::: - that you DO NOT seek compensation of any kind, monies or otherwise, in ANY FORM, from previous, current and future parties; not limited to:
- ::: -- anyone
- ::: -- everyone
- ::: -- it's author(s)
- ::: -- it's contributor(s)
- ::: -- any beneficiaries
- ::: -- users
- ::: -- distributors
- ::
- :::::::::::::::::::::::::::::::::::::::
- :: By JaCk | Release 05/04/2017 | https://pastebin.com/6vEQscEX | cbzme.bat - Creates cbz files using the 7-zip binary
- @echo off & setlocal EnableDelayedExpansion
- :: This script is based on http://alanhorkan.livejournal.com/58404.html
- :: - which was based on http://aarmstrong.org/tutorials/mass-zip-rar-to-7zip-recompression-batch-file
- :: -- "Mass Zip, RAR to 7Zip Recompression Batch File by Andrew Armstrong"
- ::
- ::
- :: Recurses through a directory and creates cbz [Comic Book Zip] files using 7z
- ::
- :: Directory Structure for the input
- :: - C:\cbme_plox\source\Comic 123\000.jpg
- :: ---- [C:\cbme_plox\source] is the base directory for [cbzme_var_source_directory]
- :: ---- 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]
- :: ---- Note: [000.jpg] is one of the images in [Comic 123]
- :::::::::::::::::::::::::::::::::::::::
- ::
- :: User Variables (Settings)
- ::
- :::::::::::::::::::::::::::::::::::::::
- 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
- 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.
- 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.
- :::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::::::
- :::: Unless you know what you're doing ::::
- :::: DO NOT CHANGE BELOW ::::
- :::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::::::
- :::::::::::::::::::::::::::::::::::::::
- ::
- :: Prompts
- ::
- :::::::::::::::::::::::::::::::::::::::
- if not defined cbzme_var_7z_bin_full_path (
- rem Try to locate the bin in the PATH system variable and set it as the default
- rem If multiple are located, script will always choose the last one on the list
- for /f "tokens=* delims=" %%s in ('where 7z.exe') do set "cbzme__input=%%~s"
- rem Ask user for input
- echo/
- echo INPUT: 7z: Please Enter the full directory path for the 7z.exe binary:
- echo INPUT: 7z: Default: [!cbzme__input!]
- set /p "cbzme__input=: "
- set "cbzme_var_7z_bin_full_path=!cbzme__input!"
- echo/
- )
- if not defined cbzme_var_source_directory (
- set "cbzme__input=%~dp0"
- echo/
- echo INPUT: Source: Please Enter the full INPUT directory path containing the sub-directories to be processed.
- echo INPUT: Source: Default: [!cbzme__input!]
- set /p "cbzme__input=: "
- set "cbzme_var_source_directory=!cbzme__input!"
- echo/
- )
- if not defined cbzme_var_output_directory (
- set "cbzme__input=%~dp0\output"
- echo/
- echo INPUT: Output: Please Enter the full directory OUTPUT path for the new cbz files
- echo INPUT: Output: Default: [!cbzme__input!]
- set /p "cbzme__input=: "
- set "cbzme_var_output_directory=!cbzme__input!"
- echo/
- )
- :: I need cleansing
- :: - forgive me father for I have been used, multiple times on multiple occasions and as a temporary placeholder...
- set "cbzme__input="
- :::::::::::::::::::::::::::::::::::::::
- ::
- :: Basic Error Checking
- ::
- :::::::::::::::::::::::::::::::::::::::
- set "cbzme__debug_flag="
- set "cbzme__fatal_flag=0"
- set "cbzme__error_count=0"
- if not exist "%cbzme_var_7z_bin_full_path%" (
- echo/
- echo ERROR: FATAL: 7zBin: Unable to access or find [%cbzme_var_7z_bin_full_pathr%]
- echo/
- set /a "cbzme__fatal_flag+=1"
- )
- if not exist "%cbzme_var_source_directory%" (
- echo/
- echo ERROR: FATAL: Source Dir: Unable to access or find [%cbzme_var_source_directory%]
- echo/
- set /a "cbzme__fatal_flag+=1"
- )
- if !cbzme__fatal_flag! gtr 0 (
- echo/
- echo ERROR: FATAL: Encountered Fatals - [!cbzme__fatal_flag!]
- echo INFO: Exiting...
- echo/
- timeout /t 15
- exit /b 1
- )
- if not exist "%cbzme_var_output_directory%" (
- echo/
- echo/ INFO: Output Dir: directory does not exist, Creating...
- mkdir "%cbzme_var_output_directory%" || (
- echo/
- echo ERROR: Output Dir: Unable to create path [%cbzme_var_output_directory%]
- echo INFO: Continuing...
- echo/
- )
- echo/
- )
- :::::::::::::::::::::::::::::::::::::::
- ::
- :: Main
- ::
- :::::::::::::::::::::::::::::::::::::::
- rem Setting default string before all the magic
- set "cbzme__d=!date:* =!" & set "cbzme__t=!time:~0,-3!"
- set "cbzme__time_string=!cbzme__d:/=.!-!cbzme__t::=.!"
- set "cbzme__time_string=!cbzme__time_string: =!"
- :: Grab a quick total count
- set "cbzme__dtcount=0"
- for /f "tokens=1* delims=" %%d in ('
- dir /b /o:-n /a:d "!cbzme_var_source_directory!"
- ') do set /a "cbzme__dtcount+=1"
- :: Give a pretty message or exit script
- if !cbzme__dtcount! gtr 0 (
- echo: INFO: CBZ: Total Directories to Process [!cbzme__dtcount!]
- echo/
- ) else (
- echo ERROR: FATAL: No Directories found to process in [!cbzme_var_source_directory!]
- echo/
- exit /b 1
- )
- :: Recurse through source directory and create cbz files in the output directory
- :: files named [z*.*] and [Thumbs.db] will automaticlly be ignored and NOT added into the new cbz file
- set "cbzme__dpcount=0"
- for /f "tokens=1* delims=" %%d in ('
- dir /b /o:-n /a:d "!cbzme_var_source_directory!"
- ') do (
- rem Assign me to my var plx
- set /a "cbzme__dpcount+=1"
- set "cbzme__dname=%%~d"
- rem set the title and print message to console
- title %~0: Processing [!cbzme__dpcount!/!cbzme__dtcount!] - !cbzme__dname!.cbz
- echo/
- echo/ ========================================
- echo/
- echo INFO: CBZ: Processing [!cbzme__dpcount!/!cbzme__dtcount!] - !cbzme__dname!.cbz
- rem call the binary with all the parameters
- 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"
- 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"
- 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"
- rem check if bin exited cleanly
- if !errorlevel! neq 0 (
- echo ERROR: CBZ: 7ZBin: Encountered unknown errors or warnings while creating [!cbzme_var_output_directory!\!cbzme__dname!.cbz]
- 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"
- echo/
- set /a "cbzme__error_count+=1"
- if defined cbzme__debug_flag timeout /t 3
- )
- echo/
- echo/ ========================================
- echo/
- rem if defined cbzme__debug_flag exit /b
- )
- echo/
- :: Checking if the error log contains anything, if not, then we delete it
- type "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log" 2>nul | findstr /c:" " 2>nul 1>nul || (
- del /q "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log"
- )
- :::::::::::::::::::::::::::::::::::::::
- ::
- :: Fin-laund
- :: git-it... FIN... LAUND... HAHA
- :: not funny, alt-f4 yourself...
- ::
- :::::::::::::::::::::::::::::::::::::::
- if !cbzme__error_count! gtr 0 (
- echo ERROR: WARNING: CBZ: 7z encountered [!cbzme__error_count!] errors or warnings
- echo ERROR: WARNING: CBZ: Please Check "%cbzme_var_output_directory%\cbz_7z_errors.!cbzme__time_string!.log" for details
- echo/
- rem Gotta clean after me-self and the kitchen-sync [-.*]
- for /f "tokens=* delims=" %%v in ('set cbzme_') do set "%%v="
- timeout /t 30 & exit /b 1
- ) else (
- rem Gotta clean after me-self and the kitchen-sync [-.*]
- for /f "tokens=* delims=" %%v in ('set cbzme_') do set "%%v="
- timeout /t 30 & exit /b 0
- )
Advertisement