Batch to remove scanner jpg (Updated 3-20-2015)

Anything non-Mylar related
Post Reply
dardack
Posts: 23
Joined: Thu Feb 13, 2014 10:28 pm

Batch to remove scanner jpg (Updated 3-20-2015)

Post by dardack »

Save as something.bat, place in each comics' directory, run.

DO NOT RUN ON COMIC THAT STARTS WITH Z. Thought someone else would like this.

Code: Select all

REM @ECHO OFF
REM Based on 
REM Mass Zip, RAR to 7Zip Recompression Batch File by Andrew Armstrong
REM http://aarmstrong.org/tutorials/mass-zip-rar-to-7zip-recompression-batch-file
REM
REM Find all .cbr and .rar files in the current directory, recompress them into .cb7 and .7zip files - deletes original

ECHO Searching for CBR CBZ and RAR files to recompress into CB7 (Comic Book Zip) archives.

for %%F in (*.cbr *.rar *.cbz) do (
ECHO Found %%F to recompress...
REM Extract...
"C:\Program Files\7-zip\7z" x "%%F" -o"%%F contents"

REM Does the directory exist? has 7zip created it correctly?
IF EXIST "%%F contents" (
REM Change directory, create zip of contents of directory...

REM Deletes original file
DEL /F "%%F"
CD "%%F contents"
REM for /f "delims=" %%i in ('dir /ad/s/b') do echo %%i
REM remove banners 
DEL /F /S /Q z*.*

REM Delete Thumbnail files. 
DEL /F /S /Q Thumbs.db
REM compression level is 9 ultra
"C:\Program Files\7-zip\7z" a -t7z "../%%~nF.cb7" * -mx9
CD ..
REM Delete the temporary extraction folder
RMDIR "%%F contents" /S /Q
ECHO Recompressed %%F to %%~nF.cb7

)
)
ECHO Search ended.

PAUSE
CLS
EXIT
Last edited by dardack on Fri Mar 20, 2015 11:57 pm, edited 1 time in total.
dardack
Posts: 23
Joined: Thu Feb 13, 2014 10:28 pm

Re: Batch to remove scanner jpg

Post by dardack »

OK I have an updated script. You can place this in your top directory. So I have my Gdrive (for google to read with comiccat wherever I am), then a comics folder under that.
Change the first 3 lines:
set BaseDir=y:\gdrive\
set ComicDir=comics\
set ZipDir=C:\Program Files\7-zip

To you base directory, comic directory (if it's comic, set base to like y:\)
Set ZipDir to your 7Zip directory.

Then once it's run you'll have a BatchErrors.txt that will show if any of the Comic's failed to extract/recompress (Usually this means the CBR/CBZ is bad, so redownload, or sometimes if using usenet there are bad ones).

Code: Select all

set BaseDir=y:\gdrive\
set ComicDir=comics\
set ZipDir=C:\Program Files\7-zip
break>"%BaseDir%BatchErrors.txt
ECHO Ran on %date% at %time% > "%BaseDir%BatchErrors.txt
FOR /R "%BaseDir%%ComicDir%" %%G in (.) DO (
	Pushd %%G
	Echo now in %%G
        for %%F in (*.cbr *.rar *.cbz) do (
		ECHO %%F
		"%ZipDir%\7z" x "%%F" -o"%%F contents"
		ECHO TEST
			REM check if 7z reported all OK
			REM LEVEL see's if >= #, have to do in backwards
			REM Can't do Zero first
		IF ERRORLEVEL 1 ( echo ERROR %%F Failed in folder %%G >> "%BaseDir%BatchErrors.txt" 
			RMDIR "%%F contents" /S /Q ) ELSE (
			REM Does the directory exist? has 7zip created it correctly?
			IF EXIST "%%F contents" (
				REM Change directory, create zip of contents of directory...

				REM Deletes original file
				DEL /F "%%F"
				CD "%%F contents"
				REM for /f "delims=" %%i in ('dir /ad/s/b') do echo %%i
				REM remove banners 
				DEL /F /S /Q z*.*

				REM Delete Thumbnail files. 
				DEL /F /S /Q Thumbs.db
				REM compression level is 9 ultra
				"C:\Program Files\7-zip\7z" a -t7z "../%%~nF.cb7" * -mx9
				CD ..
				REM Delete the temporary extraction folder
				RMDIR "%%F contents" /S /Q
				ECHO Recompressed %%F to %%~nF.cb7)
			)
		
		
	)
	Popd 
)

Methanoid
Posts: 66
Joined: Wed Jun 10, 2015 9:10 pm

Re: Batch to remove scanner jpg (Updated 3-20-2015)

Post by Methanoid »

This is close to what I was looking for and asked my son to see if he could knock up.

Some suggestions for further improvement:

Add a config switch to allow user to select output format (CBZ,CBR,CB7)

Add a strip option to remove every non-JPG/JPEG/GIF/etc - to remove silly extras added by some people like URL shortcuts or even Thumbs.db

Process to root. What I mean is when the JPEG files are in a sub directory. Bring them to root before archiving. Some readers don't process sub directory archives well!

Option to rename files. I see lots of archives where someone has named each JPG image as XYZ-LONGNAME-Comic-page-0000001.jpeg which could as easily be "P0001.jpg"
Post Reply