My final script would be this:
Code: Select all
@echo off &setlocal DisableDelayedExpansion
::http://www.dostips.com/forum/viewtopic.php?p=47747#p47747
:: Post subject: Validity of the directories and files names
::Posted: Wed Jul 13, 2016 12:26 pm by balubeto
::modified: Thu Jul 14, 2016 by thefeduke adding create as optional
Set "MaxRC=0"
call :VetDir "esd_Genuine_File_Path" "Enter the directory of the esd genuine unencrypted file:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
if "%errorlevel%" EQU "0" (
call :VetFile "esd_File" "Enter the esd unencrypted file to be converted which should be put in the %esd_Genuine_File_Path% directory:" "%esd_Genuine_File_Path%"
)
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
call :VetDir "esd_File_Path" "Enter the directory in which put the esd unencrypted file:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
call :VetDir "Windows_Files_Path" "Enter the directory in which put the Windows files:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
call :VetDir "iso_Path" "Enter the directory in which put the iso image file created:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
If "%errorlevel%" EQU "0" (
call :VetFile "iso_File" "Enter the file for the creation of the iso image in the %iso_Path% directory:" "%iso_Path%"
)
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
call :VetISOLabel iso_Label "Enter the iso image label:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
call :VetCreationDate Creation_Date "Enter the creation date of the iso image in the mm/dd/yyyy,hh:mm:ss format:"
If "%errorlevel%" GTR "%MaxRC%" Set "MaxRc=%errorlevel%"
echo.
If "%MaxRC%" NEQ "0" Echo.iso build abandoned during validation.
mv "%esd_Genuine_File_Path%\%esd_File%" "%esd_File_Path%"
Dism /Apply-Image /ImageFile:"%esd_File_Path%\%esd_File%" /Index:1 /ApplyDir:"%Windows_Files_Path%" /Verify /CheckIntegrity
Dism /Export-image /SourceImageFile:"%esd_File_Path%\%esd_File%" /SourceIndex:2 /DestinationImageFile:"%Windows_Files_Path%\sources\boot.wim" /Compress:max /Bootable /CheckIntegrity
Dism /Export-image /SourceImageFile:"%esd_File_Path%\%esd_File%" /SourceIndex:3 /DestinationImageFile:"%Windows_Files_Path%\sources\boot.wim" /Compress:max /Bootable /CheckIntegrity
Dism /Export-image /SourceImageFile:"%esd_File_Path%\%esd_File%" /SourceIndex:4 /DestinationImageFile:"%Windows_Files_Path%\sources\install.esd" /Compress:Recovery /CheckIntegrity
del "%esd_File_Path%\%esd_File%"
oscdimg -o -u2 -udfver102 -l"%iso_Label%" -t%Creation_Date% -bootdata:2#p0,e,b"%Windows_Files_Path%\boot\etfsboot.com"#pEF,e,b"%Windows_Files_Path%\efi\microsoft\boot\efisys.bin" "%Windows_Files_Path%" "%iso_Path%\%iso_file%"
pushd "%Windows_Files_Path%" && ( rd /S /Q "%Windows_Files_Path%" 2>nul & popd )
rd "%Windows_Files_Path%"
goto :eof
:VetDir
setlocal DisableDelayedExpansion
::http://www.dostips.com/forum/viewtopic.php?p=47682#p47682
:: Post subject: Re: Check the validity of the directories and files names
::Posted: Sun Jul 10, 2016 5:07 pm by aGerman
::modified: Thu Jul 14, 2016 by thefeduke adding create as optional
:loop
set "%~1="
set /p "%~1=%~2 "
call :validate "%~1" validpath
if errorlevel 2 Exit /b 1
if errorlevel 1 goto loop
call echo Valid path: "%validpath%"
rem.pause
endlocal &set "%~1=%validpath%"
exit /b
:validate
setlocal EnableDelayedExpansion
set "p=!%~1!"
:: characters /<>|*?" are invalid
for /f delims^=/^<^>^|*?^" %%i in ("!p!") do (
setlocal DisableDelayedExpansion
set "s=%%i"
setlocal EnableDelayedExpansion
if "!s!" neq "!p!" (
endlocal&endlocal&endlocal
echo Invalid character found.
exit /b 1
)
endlocal&endlocal
)
:: if the 2nd and 3rd characters are not :\ it's not a local absolute path
if "!p:~1,2!" neq ":\" (
endlocal
echo No absolute path entered.
exit /b 1
)
:remove_trailing_backslash if any
if "!p:~-1!"=="\" (set "p=!p:~,-1!"&goto remove_trailing_backslash)
:: check if the path exists
if not exist "!p!\" (
echo The entered path doesn't exist.
Call CHOICE /C BRC /N /M "Press B to Build, R to Retry with a different path or C to Cancel."
If "!errorlevel!" EQU "3" (
endlocal &set "%~2="
exit /b 2
)
If "!errorlevel!" EQU "2" (
endlocal
exit /b 1
)
If "!errorlevel!" EQU "1" (
mkdir !p!
)
)
:: try to write a temporary file in order to check if you have permissions
2>nul (>"!p!\test.~tmp" type nul) || (
endlocal
echo Access denied.
exit /b 1
)
:: file deletion fails if the path contains consecutive backslashes
2>nul del "!p!\test.~tmp" || (
endlocal
echo Multiple backslashes found.
exit /b 1
)
endlocal &set "%~2=%p%"
exit /b 0
:VetFile
setlocal DisableDelayedExpansion
::http://www.dostips.com/forum/viewtopic.php?p=47682#p47682
:: Post subject: Re: Check the validity of the directories and files names
::Posted: Sun Jul 10, 2016 5:07 pm by aGerman
::modified: Thu Jul 15, 2016 by thefeduke - adding semi-autmatic file selection
set "folder=%~3"
set "files=0"
For /f "usebackq tokens=1-2" %%F in (`dir "%folder%" /a-d`) DO (
If /I "%%~G" EQU "File(s)" Set "files=%%~F"
)
If "%files%" EQU "0" (Echo.No files in '%folder%'.&endlocal &set "%~1=" &Exit /b 1)
If "%files%" EQU "1" For /f "usebackq tokens=1" %%V in (`dir "%folder%" /b /a-d`) DO Set "Valid=%%V"
If "%files%" EQU "1" (
Echo.'%valid%' is the only file in '%folder%'.
endlocal &set "%~1=%valid%"
Exit /b 0
)
dir "%folder%" /b /a-d
Echo.Enter one of the above files in '%folder%'.
:loopfile
set "%~1="
set /p "%~1=%~2 "
call :validatefile "%~1" validFile
if errorlevel 2 Exit /b 1
if errorlevel 1 goto loopfile
call echo Valid file: "%validfile%"
rem.pause
endlocal &set "%~1=%validfile%"
exit /b
:validatefile
setlocal EnableDelayedExpansion
set "p=!%~1!"
:: characters /<>|*?" are invalid
for /f delims^=/^<^>^|*?^" %%i in ("!p!") do (
setlocal DisableDelayedExpansion
set "s=%%i"
setlocal EnableDelayedExpansion
if "!s!" neq "!p!" (
endlocal&endlocal&endlocal
echo Invalid character found.
exit /b 1
)
endlocal&endlocal
)
:: check if the file exists
if not exist "%folder%\!p!" (
echo The entered file doesn't exist.
Call CHOICE /C RC /N /M "Press R to Retry with a different file or C to Cancel."
If "!errorlevel!" EQU "2" (
endlocal &set "%~2="
exit /b 2
)
If "!errorlevel!" EQU "1" (
endlocal
exit /b 1
)
)
endlocal &set "%~2=%p%"
exit /b 0
but I have some problems:
1) Even if I put an esd file in the %esd_Genuine_File_Path% directory, the %esd_File% variable is always empty. Why? It is possible insert it directly, logically controlling its validity of its name and its existence?
2) Since the iso file is created by the script, how do I ensure that the script does not verify its existence? In other words, the script should only check the validity of its name with its extension.
3) How do I create the %iso_Label% and %Creation_Date% procedures to verify the validity of the volume label of the iso file and the creation date of its files?
Thanks
Bye