balubeto wrote:Excuse me, but this script
Code: Select all
echo/ & set ArgCount=0 & for %%i in (%*) do (set /a ArgCount+=1)
if %ArgCount% neq 4 (echo The arguments number is incorrect.) & goto end
:end
assumes that its arguments are insert directly from the command line. Now, I would like to create a script like this
Code: Select all
set /p Windows_Files_Path="Enter the directory in which put the content of the ^"Windows Setup Media^" volume image:"
set /p iso_Path="Enter the directory in which put the iso image file created:"
set /p esd_File_Path="Enter the directory in which put the esd unencrypted file:"
set /p esd_File="Enter the file to be converted which should be put in the %esd_File_Path% directory:"
that when it will be run, ask to enter the arguments.
How do I check whether the entered values are valid? If they are not valid, the script will have to immediately repeat the relative entry without using the goto command to create a loop.
Here's what I'm hearing:
- You want to be able to accept arguments from the command line.
- You want to be able to prompt for missing argument values.
- You want to validate the values given, regardless of the source.
- If an argument value is invalid, you want to require the user to enter a new value, and repeat until a valid argument is entered.
Each of these things is very easy, but you are adding in some complications for no apparent reason.
To validate file and folder paths, it is usually enough to confirm that they exist, and if not, create them. You are asking to require absolute paths instead of relative, but aren't saying why. While this can be done, it's a bit of a pain, so we want to either understand what your use case is, so we can handle any other related weirdness, or explain to you why you don't need that, and keep the code simple and robust.
To do a repetitive task, you use a loop. If there are a fixed number of iterations, you use the FOR command. If there are an undefined, potentially infinite number of iterations like you are asking for, you use the GOTO command. That's what it's for. Some very competent people have suggested this already, and you are rejecting it without saying why. Before anyone invests time in creating and testing exotic solutions to avoid GOTO, you need to explain why it won't work for you.
So, to get the help you are asking for, please answer these questions:
- Why do you need absolute instead of relative paths?
- What are ALL of the conditions that arguments need to meet to be valid?
- Why do you object to using the GOTO command?