Here is a batch script for processing files with IV.
I did my best to make it versatile and easily configurable.
I did my best to make it versatile and easily configurable.
Code:
@Echo off & SetLocal EnableDelayedExpansion ::: Irfanize.cmd ::: A script for processing images with IrfanView ::: Usage: drag&drop a file or folder onto the script ::: or run the script in a folder that you want processed ::: or specify a file/folder on the command line ::: Adjust options below to make script do what you need :::::::::::::::::::::::::::: Edit this part :::::::::::::::::::::::::::: Set IrfanExe= ::: Leave blank if IV is installed in default location ::: (64-bit takes precedence if both versions are installed) ::: Otherwise specify full path to executable, without quotes ::: e.g. IrfanExe=D:\My Progs\IrfanView\i_view32.exe Set IniDir= ::: Leave blank to use the default configuration file ::: Otherwise specify a folder that contains i_view32/i_view64.ini ::: e.g. IniDir=%~dp0 if .ini is in script folder Set InputExt= ::: Specify one or more input file types separated by commas or spaces ::: e.g. InputExt=jpg,png,gif ::: Leave blank to accept all file types ::: InputExt is only used when processing folders Set Recursive=No ::: Yes=process subfolders Set ActionParams= ::: Specify what to do with images; see IV help->Command Line Options ::: e.g. ActionParams=/crop=(0,0,128,128,0) /vflip /invert ::: Leave blank if you are simply looking to convert between formats Set OutputExt= ::: Specify output format, e.g. OutputExt=png ::: Leave blank to keep the source file type Set OutputSuffix= ::: You can append a string to output filename ::: e.g. if OutputSuffix=_new, then img.jpg->img_new.jpg Set OutputAutoRename=No ::: Yes=autorename output if file already exists, e.g. img_new(1).jpg ::: Note: utilizes /makecopy option introduced in IV 4.38 Set OutputDir= ::: If you specify a name, e.g. OutputDir=IVOutput ::: output will be saved to that subfolder (in source folder) ::: You can also specify an absolute path, e.g. OutputDir=D:\Pics ::: Leave blank to save output to the source folder (not recommended) Set OverwriteInput=No ::: Yes=output will be same as input, i.e. replace source file(s) ::: (overrides OutputExt, OutputSuffix, OutputAutoRename, OutputDir) Set DeleteInput=No ::: Yes=delete source file(s) after processing ::: Not deleted if OverwriteInput=Yes or if processing failed ::: In folder mode this option is only allowed if InputExt is specified :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: If not %1.==. If not exist "%~f1" Echo Invalid path specified. & Goto End If not "%IrfanExe%"=="" (If not exist "%IrfanExe%" (Echo Invalid IrfanView executable specified. & Goto End)) Else ( If exist "%ProgramFiles%\IrfanView\i_view64.exe" (Set "IrfanExe=%ProgramFiles%\IrfanView\i_view64.exe") Else ( If exist "%ProgramW6432%\IrfanView\i_view64.exe" (Set "IrfanExe=%ProgramW6432%\IrfanView\i_view64.exe") Else ( If exist "%ProgramFiles%\IrfanView\i_view32.exe" (Set "IrfanExe=%ProgramFiles%\IrfanView\i_view32.exe") Else ( If exist "%ProgramFiles(x86)%\IrfanView\i_view32.exe" (Set "IrfanExe=%ProgramFiles(x86)%\IrfanView\i_view32.exe") Else ( Echo IrfanView executable could not be located. & Goto End))))) Set K=!IrfanExe:~-12,8! If not "%IniDir%"=="" ( If "%K%"=="i_view64" ( If not exist "%IniDir%\i_view64.ini" (Echo i_view64.ini is missing in specified dir. & Goto End)) Else ( If "%K%"=="i_view32" ( If not exist "%IniDir%\i_view32.ini" (Echo i_view32.ini is missing in specified dir. & Goto End))) Set "IniDir=/ini=^"%IniDir%^"" ) If /I "%OverwriteInput%"=="Yes" ( Set OutputExt= Set OutputSuffix= Set OutputDir= ) Else ( If "%OutputExt%"=="" (If "%OutputSuffix%"=="" (If "%OutputDir%"=="" ( Echo The script isn't set up to output anything. See usage info inside. & Goto End))) If /I "%OutputAutoRename%"=="Yes" Set "ActionParams=%ActionParams% /makecopy" If not "%OutputDir%"=="" Set "OutputDir=%OutputDir%\" ) If "%K%"=="i_view64" (Echo IrfanView ^(64-bit^)) Else ( If "%K%"=="i_view32" (Echo IrfanView ^(32-bit^))) If %1.==. Goto FolderMode If exist "%~f1\*.*" Goto FolderMode :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Echo( Echo Processing %~nx1... If "%OutputExt%"=="" (Set OutputExt=%~x1) Else (Set OutputExt=.%OutputExt%) If /I "%OverwriteInput%"=="Yes" ( "%IrfanExe%" ""%~f1" %IniDir% %ActionParams% /convert=%~f1 /silent" If Errorlevel 2 (Echo Error saving output^^!) Else ( If Errorlevel 1 (Echo Error loading file^^!) ) ) Else ( If /I not "%~f1"=="%OutputDir%%~n1%OutputSuffix%!OutputExt%!" ( If /I not "%~f1"=="%~dp1%OutputDir%%~n1%OutputSuffix%!OutputExt%!" ( "%IrfanExe%" ""%~f1" %IniDir% %ActionParams% /convert=%OutputDir%%~n1%OutputSuffix%!OutputExt! /silent" If Errorlevel 2 (Echo Error saving output^^!) Else ( If Errorlevel 1 (Echo Error loading file^^!) Else ( If /I "%DeleteInput%"=="Yes" ( CD /D "%~dp1" If exist "%OutputDir%%~n1%OutputSuffix%!OutputExt%!" ( Del /F /Q "%~f1" ) ) ) ) ) ) ) Echo( Echo Finished. Goto End :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :FolderMode If %1.==. (Set "SrcDir=%~dp0") Else (Set "SrcDir=%~f1\") If not "%InputExt%"=="" ( Set I= Set L= If /I "%Recursive%"=="Yes" (Echo Scanning for files with specified extension^(s^)...) For %%G in (%InputExt%) Do ( Set I=!I!*.%%G, If exist "%SrcDir%*.%%G" (Set L=found) Else ( If /I "%Recursive%"=="Yes" ( CD /D "%SrcDir%" For /D /R %%J in ("*") Do (If exist "%%J\*.%%G" Set L=found) ) ) ) If not "!L!"=="found" Echo No files with specified extension^(s^) found. & Goto End Set InputExt=!I:~0,-1! ) Else (Set InputExt=*.*) If not "%OutputExt%"=="" Set OutputExt=.%OutputExt% Echo( Echo Processing... Echo( Echo %SrcDir% Set K=1 :SrcDirDepth Set J=%K% For /F "tokens=%K% delims=\" %%G in ("%SrcDir%") Do (Set /A K+=1) If not "%J%"=="%K%" Goto SrcDirDepth Set /A K-=1 Set FileCount=0 Set ErrorCount=0 If /I "%Recursive%"=="Yes" ( Set "L=%SrcDir%" For /R "%SrcDir%" %%G in (%InputExt%) Do ( If not "%%~fG"=="%~f0" ( If /I not "%%~dpG"=="%OutputDir%" ( Set "H=%%~pG" Set "H=!H:~0,-1!" For %%I in ("!H!") Do (Set H=%%~nxI) Set "H=!H!\" If /I not "!H!"=="%OutputDir%" ( If /I not "!L!"=="%%~dpG" ( For /F "tokens=%K%* delims=\" %%I in ("%%~dpG") Do ( Echo( Echo %%J ) ) Echo( Echo %%~nxG If "%OutputExt%"=="" Set OutputExt=%%~xG If /I "%OverwriteInput%"=="Yes" ( "%IrfanExe%" ""%%~fG" %IniDir% %ActionParams% /convert=%%~fG /silent" If Errorlevel 2 (Echo Error saving output^^! & Set /A ErrorCount+=1) Else ( If Errorlevel 1 (Echo Error loading file^^! & Set /A ErrorCount+=1) Else ( Set /A FileCount+=1 ) ) ) Else ( If /I not "%%~fG"=="%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( If /I not "%%~fG"=="%%~dpG%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( "%IrfanExe%" ""%%~fG" %IniDir% %ActionParams% /convert=%OutputDir%%%~nG%OutputSuffix%!OutputExt! /silent" If Errorlevel 2 (Echo Error saving output^^! & Set /A ErrorCount+=1) Else ( If Errorlevel 1 (Echo Error loading file^^! & Set /A ErrorCount+=1) Else ( Set /A FileCount+=1 If /I "%DeleteInput%"=="Yes" ( If not "%InputExt%"=="*.*" ( CD /D "%%~dpG" If exist "%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( Del /F /Q "%%~fG" ) ) ) ) ) ) ) ) Set "L=%%~dpG" ) ) ) ) ) Else ( CD /D "%SrcDir%" For %%G in (%InputExt%) Do ( If not "%%~fG"=="%~f0" ( Echo( Echo %%~nxG If "%OutputExt%"=="" Set OutputExt=%%~xG If /I "%OverwriteInput%"=="Yes" ( "%IrfanExe%" ""%%~fG" %IniDir% %ActionParams% /convert=%%~fG /silent" If Errorlevel 2 (Echo Error saving output^^! & Set /A ErrorCount+=1) Else ( If Errorlevel 1 (Echo Error loading file^^! & Set /A ErrorCount+=1) Else ( Set /A FileCount+=1 ) ) ) Else ( If /I not "%%~fG"=="%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( If /I not "%%~fG"=="%%~dpG%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( "%IrfanExe%" ""%%~fG" %IniDir% %ActionParams% /convert=%OutputDir%%%~nG%OutputSuffix%!OutputExt! /silent" If Errorlevel 2 (Echo Error saving output^^! & Set /A ErrorCount+=1) Else ( If Errorlevel 1 (Echo Error loading file^^! & Set /A ErrorCount+=1) Else ( Set /A FileCount+=1 If /I "%DeleteInput%"=="Yes" ( If not "%InputExt%"=="*.*" ( CD /D "%%~dpG" If exist "%OutputDir%%%~nG%OutputSuffix%!OutputExt%!" ( Del /F /Q "%%~fG" ) ) ) ) ) ) ) ) ) ) ) Echo( Echo Finished. Echo( Echo %FileCount% files successfully processed. Echo %ErrorCount% errors. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :End Echo( Pause Echo(
Comment