0

I Have a list of folders on DVD that I would like to process one at a time. I am trying to use a FOR command to pass through information to set as the variable in a 2nd batch file.

I am having the user input two variables, then I'd like a 3rd variable to come from my list of folders. Then run a 2nd batch file for each folder on the DVD:

echo enter Drive letter
set /p Drive=

echo enter diskname
set /p diskname=

FOR /F %%i IN ('dir /ad /b e:\') DO set book=%%i


call Load.bat %drive% %diskname% %book%

Then in my load.bat I have:

Set drive=%1
Set diskname=%2
Set book=%3

Copy %drive%\%book% \\server\%book%

The script will run fine on ONE folder on the DVD. How can I get this to loop through each folder?

Thanks!

1 Answers1

0
FOR /F %%i IN ('dir /ad /b e:\') DO (
 set book=%%i
 call Load.bat %drive% %diskname% %%i
)

Note that if any of the paramaters may contains separators like spaces, the parameter needs to be "quoted" (must be double quotes) and you should then use %~n (where n=1..3 in your case) to acess the parameter in the subsidiary batch.

the ( must be on the same physical line as the do keyword. The other data may be on seperate lines, or may be all on one line if you wish, but in that case they need to be separated by &, eg

FOR...DO set book=%%i&call Load.bat "%drive%" "%diskname%" "%%i"

Note that if the data is all on one line, the parentheses are not required. I've omitted the body of the for loop for brevity's sake and inserted the quotes for each parameter, so the subsidiary batch would require %~1..%~3 to strip off those quotes.

Actually, you don't need to send the data as parameters. The subsidiary batch can access (and change) the environment variables, so those three parameters are already present in the variables when the subsidiary batch is executed.

Magoo
  • 77,302
  • 8
  • 62
  • 84