Is there a way to set each line of a txt document as a different variable in a batch file? I have got a txt file with all drives found on the computer. How can I set each line (for each drive) as a different variable, if this is possible at all?
I have a file which writes all avalible drives in a text file. I want to read this file out and set a different variable for each line of text. For example:
DeviceID
C:
D:
E:
Now "DeviceID" would be the first variable. "C:" "D:" and "E:" are all getting individual variables. I hope you get what I mean.
Thanks in advance!
Okay so I've tried this:
@echo off
setlocal enabledelayedexpansion
set i=0
for /f "tokens=2 delims=:=" %%a in ('wmic logicaldisk get name /value ') do (
set /a i+=1
set drive[!i!]=%%a
)
set drive
pause
copy %0 %drive[1]%:\%random%.bat
pause
And it works pretty well. But I want to copy the currently executed file to all drives found without typing:
copy %0 %drive[1]%:\currentlyexecutedfile.bat
copy %0 %drive[2]%:\currentlyexecutedfile.bat
copy %0 %drive[3]%:\currentlyexecutedfile.bat
copy %0 %drive[4]%:\currentlyexecutedfile.bat
Is there a way to do this, without knowing how many drives there are and without causing errors?