Collecting information from user to run comma

Hewlett-packard / Hp compaq 6910p
April 6, 2010 at 09:01:39
Specs: Microsoft Windows XP Professional, 2.393 GHz / 2039 MB
I'm creating a batch file to collect information from the user so that I can use it to call a java command at the end of the batch file.

What I want to be able to do is prompt the user for multiple directories, one at a time and then concatenate them together when the user is done entering directories (signified by entering Ctrl-Z) for the java command.

I've tried this:

for /f %%d in (`set /p dir="Entery Directory (Ctrl-Z to stop): "`) do set dirs=%dir%;dirs

and I get an error say that the syntax was incorrect.

See More: Collecting information from user to run comma

Report •

April 6, 2010 at 09:09:05
instead of forcing the victim to do ctrl-z, i would just use a null entry and let it go at that.
restructure the code into a loop:
set dirs=
set sep=
set xx=
set /p xx=directory:
if "%xx%" equ "" goto :two
set dirs=%dirs%%sep%%xx%
set sep=,
goto :one
echo list is:%dirs%

Report •

April 6, 2010 at 09:37:13
That did it. Thanks!

Now, I'd like to be able to put that into a sub-routine inside my batch file so that I can use for other input that is formatted the same.

I have:

set dirs=

call :promptUser dirs Directory
echo $dirs
:promptUser list string
set value=
set /p value="Enter %string% (blank when done): "
if "%value%" equ "" goto :EOF
   set list=%list%;%value%
   goto one:

My problem is how to return the value of

so that it populates
from where it was called.

Report •

April 6, 2010 at 15:04:28
internal subroutines do not require that variables be passed the way you did. they can be passed to the subroutine that way, but not back that way. Also, the variables passed in this manner are referenced as positionals: %1, %2. Variables are somewhat global. So:
set directory=something
set xx=
call :promptuser %directory%
echo heres the list: %dirs%
goto :eof
set /p xx=enter items for %1:
if xx="" then goto :eof
set dirs=%dirs%;%xx%
goto :promptuser
::----- end
you could just as well do this:
call :promptuser
set /p xx=enter items for %directory%
i'm not sure if there's any reason to do it one way vs the other.

Report •

Related Solutions

Ask Question