@echo off
REM 2019-03-28
cls
echo.
echo Runs MakePartImage.cmd on all files
echo.
echo Usage: %~n0   [folder-path]
echo        %~n0   folder-path   FAT32      (runs with suggested filename)
echo        %~n0   folder-path   FAT32   *  (runs with suggested filename and suggested size)
echo.
echo e.g.   %~n0   G:\ISOS\      FAT32   *
echo.

REM Add rEFInd to all images
:: set DOREFIND=1
REM Add WinPE and REFIND to all images
:: set DOREFIND=1&set DOWIM=1

pushd "%~dp0"
set FOLDERPATH=%~1
if /i "%~2"=="FAT32" set FMT=FAT32
if /i "%~2"=="NTFS"  set FMT=NTFS
if "%FMT%"=="" set FMT=
if "%~3"=="*" set WCARD=*
if not "%~3"=="*" set WCARD=
if "%~1"=="" set /p FOLDERPATH=Folder path containing files (e.g. C:\temp\My ISOs) : 
echo.
if @%FOLDERPATH%@==@@ echo NO PATH! & pause & goto :EOF
if @^%FOLDERPATH:~-1,1%@==@^"@ set FOLDERPATH=%FOLDERPATH:~1,-1%
if not "%FOLDERPATH:~-1,1%"=="\" set FOLDERPATH=%FOLDERPATH%\
echo Path=%FOLDERPATH%
echo.

set MATCH=*.iso
if "%~1"=="" set /p MATCH=Enter filespec (e.g. a*.iso, *.ima, *.zip) [ENTER=*.iso] : 
echo.
echo Filespec match=%MATCH%
echo.
set IFNEXIST=if not exist %%~dpnA.imgPTN

set /P ask=Only make missing .imgPTN files ([Y]/N) : 
echo.
if /i "%ask%"=="N" set IFNEXIST=& echo All .imgPTN files will be re-made
if not "%IFNEXIST%"=="" echo Only missing .imgPTN files will be re-made
echo.

if exist ..\MakePartImage.cmd pushd ..
if /i "%FMT%"=="NTFS" set /p AUTORUN=Do you want most questions to be answered automatically with NTFS + AUTORUN? ([Y]/N) : 
if /i "%FMT%"=="NTFS" if /i not "%AUTORUN%"=="N" set AUTORUN=Y& set WCARD=*& set FMT=NTFS& set AUTOSYSL=Y& goto :doit

if /i "%FMT%"=="FAT32" set /p AUTORUN=Do you want most questions to be answered automatically with FAT32 + AUTORUN? ([Y]/N) : 
if /i "%FMT%"=="FAT32" if /i not "%AUTORUN%"=="N" set AUTORUN=Y& set WCARD=*& set FMT=FAT32& set AUTOSYSL=Y& goto :doit

if /i "%FMT%"=="" set /p AUTORUN=Do you want most questions to be answered automatically with FAT32 + AUTORUN? ([Y]/N) : 
if /i "%FMT%"=="" if /i not "%AUTORUN%"=="N" set AUTORUN=Y& set WCARD=*& set FMT=FAT32& set AUTOSYSL=Y& goto :doit

:doit
echo.
echo Looking in %FOLDERPATH% for %MATCH% files...
::suppress launching of Explorer
set NOEXPLORER=1
for /R "%FOLDERPATH%" %%A in (%MATCH%) do %IFNEXIST% call MakePartImage "%%A" * %FMT% %WCARD%
set NOEXPLORER=
set AUTORUN=
echo.
echo FAILED conversions
echo ==================
echo Checking for %MATCH% files with no matching .imgPTN files...
echo.
for /R "%FOLDERPATH%" %%A in (%MATCH%) do if not exist %%~dpnA.imgPTN echo %%A & set BB=1
echo.
echo.
if "%BB%"=="" echo No missing .imgPTN files - all is OK!
set FOLDERPATH=
echo.
popd

echo Finished.

pause



