Код:

@echo off
setlocal enableextensions enabledelayedexpansion
set sSourceFolder=%~1
if not defined sSourceFolder (
echo Usage: %~nx0 ^<Source folder^>
exit /b 2
)
if exist "%sSourceFolder%\." (
for /f "usebackq delims=" %%i in (
`@"%systemroot%\system32\mshta.exe" "javascript:try {with(new ActiveXObject('Scripting.FileSystemObject')) {GetStandardStream(1).Write(GetFolder('%sSourceFolder:\=\\%').Size)}};catch (e){};close();"`
) do set sPrevFolderSize=%%i
echo Previously size [!sPrevFolderSize!].
cd /d "%sSourceFolder%"
:: Инициализация Секундомера
:: http://forum.oszone.net/post-2275768-8.html
%USERPROFILE%\Desktop\Util\timemer my_backup start
:: Оптимизация JPG
:: jpegtran http://jpegclub.org/jpegtran/
if not exist %sSourceFolder%\*.jpg if not exist %sSourceFolder%\*.jpeg goto mp3
pause
md "%sSourceFolder%\OptimizedJPEGS"
for %%i in (*.jpg *.jpeg) do %USERPROFILE%\Desktop\Util\jpegtran.exe -optimize -progressive -copy none "%%i" "%sSourceFolder%\OptimizedJPEGS\%%i"
move /Y "%sSourceFolder%\OptimizedJPEGS\*.*" "%sSourceFolder%"
rd "%sSourceFolder%\OptimizedJPEGS"
:mp3
:: Оптимизация MP3
:: mp3packer 2.04
if not exist %sSourceFolder%\*.mp3 goto gif
md "%sSourceFolder%\OptimizedMP3"
for %%i in (*.mp3) do %USERPROFILE%\Desktop\Util\mp3packer64.exe -f -z --workers 3 "%%i" "%sSourceFolder%\OptimizedMP3\%%i"
move /Y "%sSourceFolder%\OptimizedMP3\*.*" "%sSourceFolder%"
rd "%sSourceFolder%\OptimizedMP3"
:gif
:: Оптимизация GIF
:: gifsicle 1.87 9.Dec.2014 http://www.lcdf.org/gifsicle/
if not exist %sSourceFolder%\*.gif goto bmp
for %%i in (*.gif) do %USERPROFILE%\Desktop\Util\gifsicle.exe -b -O3 "%%i"
:bmp
:: Конвертирование BMP в PNG
if not exist %sSourceFolder%\*.bmp goto png
md "%sSourceFolder%\OptimizedBMP_PNG"
for %%i in (*.BMP) do "%USERPROFILE%\Desktop\Util\pngout.exe" "%%i" "%sSourceFolder%\OptimizedBMP_PNG\%%i"
move /Y "%sSourceFolder%\OptimizedBMP_PNG\*.*" "%sSourceFolder%"
rd "%sSourceFolder%\OptimizedBMP_PNG"
:png
:: Оптимизация PNG
:: PNGOUT http://advsys.net/ken/utils.htm
if not exist %sSourceFolder%\*.png goto fin
for %%i in (*.png) do "%USERPROFILE%\Desktop\Util\pngout.exe" "%%i"
move /Y "%sSourceFolder%\OptimizedBMP_PNG\*.*" "%sSourceFolder%"
rd "%sSourceFolder%\OptimizedBMP_PNG"
md "%sSourceFolder%\defluff"
for %%i in (*.png) do %USERPROFILE%\Desktop\Util\defluff.exe <"%%i" > "%sSourceFolder%\defluff\%%i"
move /Y "%sSourceFolder%\defluff\*.*" "%sSourceFolder%"
rd "%sSourceFolder%\defluff"
for %%i in (*.png) do "%USERPROFILE%\Desktop\Util\DeflOpt.exe" "%%i"
:fin
:: Получаем время работы программы
%USERPROFILE%\Desktop\Util\timemer my_backup view
for /f "usebackq delims=" %%i in (
`@"%systemroot%\system32\mshta.exe" "javascript:try {with(new ActiveXObject('Scripting.FileSystemObject')) {GetStandardStream(1).Write(GetFolder('%sSourceFolder:\=\\%').Size - !sPrevFolderSize!)}};catch (e){};close();"`
) do set sDifference=%%i
echo Difference after working is [!sDifference!].
) else (
echo Can't find source folder [%sSourceFolder%].
exit /b 1
)
endlocal
exit /b 0