2
votes

I am writing a batch file that copies files from all the removable drives inserted that match a certain disk label. In this case "VIDEO"...

Existing code simply displays the detected drives and asks user to input themselves the drive letters.

It should never be more than 4 drives but should display an error if there are more than 4 detected.

QUESTION: How can I automatically set disk1, disk2, disk3, disk4 instead of forcing the user to do this?

EXISTING CODE:

echo Here are the drive letters of VIDEO cards  inserted:
for /f %%D in ('wmic volume get DriveLetter^, Label ^| find "VIDEO"') do echo/|set /p ="%%D   "
set "drive1="
if "%drive1%"=="" if %Cards% geq 1 set /p drive1= What is the FIRST video drive letter (example: d:): 
set "drive2="
if "%drive2%"=="" if %Cards% geq 2 set /p drive2= What is the SECOND video drive letter (example: d:): 
...etc..
2

2 Answers

2
votes

nearly there. Just set your variable instead of the echo/|set /p construct and implement a counter:

@echo off
setlocal enabledelayedexpansion
set count=0
for /f %%D in ('wmic volume get DriveLetter^, Label ^| find /i "Video"') do ( 
  set /a count+=1
  set drive!count!=%%D
)
echo %count% drives found:
set drive 2>nul
if %count% gtr 4 echo too much... 
0
votes

I have a batch file that does kind of the same thing. Here's a part of the code :

@echo off
set yes=true
>nul find "%yes%" F:\hold.txt && (
  echo F:/ exists
) || (
  echo F:/ does not exist
)
pause

So in the drive that is inserted into F:/ I have a text file that is called "hold.txt" and in the file I just have 'true' typed in the text file. If you understand batch and the FIND command, you'll see why this works. It finds the file, and the text string, and tells the program to print "F:\ exists" in the fourth line of code above. Hope this helps!