It is hard to see, what you want to do:
See
this post on page 1:
balubeto wrote:while, if a user enters an X:\A\B.ext directory that does not exist, the script should consider it invalid.
And your second last post above:
balubeto wrote: when I insert a new directory nonexistent, the script does to know correctly that this directory does not exist but, then, it continues to repeat the request, and it does not automatically go to the next request.
The path either "valid and not invalid" or "not valid and invalid":
It cannot be both "valid and invalid".
Actually the path is invalid if it does not exist, so you get this behaviour.
Sidenote:
The function ":setValidPath" checks if a given path is valid within the section ":validatePath":
If the path is not valid then it asks the user to enter a new (hopefully valid) path,
else the path is valid and the function stores the path within the specified environment variable and returns to the calling context.
In
a post of your last thread you wanted this loop (if i haven't misinterpreted what you've written):
balubeto wrote:When I press only the Enter key when the script displays an entry, it is possible to use a For loop or other structure to redisplay the entry?
In addition:
I'm still unsure why you don't just create the path and check if it exists (removing the sample validation example) - it seems you seem want to create the directory:
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
call :setValidPath "Windows_Files_Path" "%~1" "Enter the directory in which put the content of the ""Windows Setup Media"" volume image:"
call :setValidPath "iso_Path" "%~2" "Enter the directory in which put the iso image file created:"
call :setValidPath "esd_File_Path" "%~3" "Enter the directory in which put the esd unencrypted file:"
call :setValidFile "esd_File" "%~4" "Enter the file to be converted which should be put in the %esd_File_Path% directory:"
echo(
echo Result:
echo Windows_Files_Path: "%Windows_Files_Path%"
echo iso_Path : "%iso_Path%"
echo esd_File_Path : "%esd_File_Path%"
echo esd_File : "%esd_File%"
:: put your code here
endlocal
goto :eof
:setValidPath
:: %~1 variable to set
:: %~2 default value
:: %~3 text if default value is invalid
setlocal
set "input=%~2"
set "text=%~3"
set "first=1"
:validatePath
set "invalid="
:: validating
setlocal EnableDelayedExpansion
if not defined invalid for /f tokens^=1*^ delims^=/^<^>^|*?^" %%a in ("#!input!#") do if not "%%~b" == "" set "invalid=Invalid character found."
endlocal & set "invalid=%invalid%"
if not defined invalid for /f "tokens=1* delims=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" %%a in ("%input:~0,3%") do if not "%%~a" == ":\" set "invalid=No absolute path entered."
if not defined invalid if not "%input:\\=##%" == "%input%" set "invalid=Double backslashes."
if not defined invalid if not exist "%input%" md "%input%"
if not defined invalid if not exist "%input%" set "invalid=The Path you specified for %~1 ^("%input%"^) is invalid."
if not defined invalid for %%a in ("%input%") do for /f "tokens=1* delims=dD" %%b in ("-%%~aa") do if "%%~c" == "" set "invalid=Name collision: File found, but path needed."
if not defined invalid if not "%input:~-1%" == "\" 2>nul (>>"%input%\test.~tmp" type nul) && del "%input%\test.~tmp" || set "invalid=Access denied."
if not defined invalid if "%input:~-1%" == "\" 2>nul (>>"%input%test.~tmp" type nul) && del "%input%test.~tmp" || set "invalid=Access denied."
if not defined invalid endlocal & set "%~1=%input%" & echo Valid: %~1=%input%& goto :eof
echo(Invalid: %invalid%
set /P ^"input=%text:""="% "
goto :validatePath
:setValidFile
:: %~1 variable to set
:: %~2 default value
:: %~3 text if default value is invalid
setlocal
set "input=%~2"
set "text=%~3"
set "first=1"
:validateFile
set "invalid="
:: validating
if not defined invalid if "" == "%input%" set "invalid=The Filename you specified for %~1 is the empty string."
setlocal EnableDelayedExpansion
if not defined invalid for /f tokens^=1*^ delims^=^\^:/^<^>^|*?^" %%a in ("#!input!#") do if not "%%~b" == "" set "invalid=Invalid character found."
endlocal & set "invalid=%invalid%"
if not defined invalid 2>nul (>>"%input%.~tmp" type nul) && del "%input%.~tmp" || set "invalid=Access denied."
if not defined invalid endlocal & set "%~1=%input%" & echo Valid: %~1=%input%& goto :eof
echo(Invalid: %invalid%
set /P ^"input=%text:""="% "
goto :validateFile
Or do you want to have differet validity checks for the different pathes?
If you want, then just describe when the different directories (stored in "Windows_Files_Path", "iso_Path", and "esd_File_Path"; also maybe the same for the "esd_File") is valid (== function doesn't loop anymore).
penpen
Edit: I've added aGerman's validity checks; i also modified them to be used within my validity chain style.