1

I want to set the command outpus (multiple lines) as variables, depending on how many lines there are. First I want to export all accessable drives on the computer to a txt file:

    wmic logicaldisk get name>drivesvar.txt

Then read out these lines again and set the different drives as variables.

I tried alot witf for /f commands, but it didnt work so far. Would be glad, if someone could help me ! Thank you in advance.

6
  • Somehow this feels more at home over at SuperUser than here, but I may be wrong. Commented Mar 25, 2016 at 13:39
  • 1
    @Shark this is nicely in the scope of programming. (Well - one could argue that the question is not on topic here, because OP didn't show us his failing code) Commented Mar 25, 2016 at 14:33
  • 2
    @Shark: Superuser: "Is your question about computer software or computer hardware?" Stackoverflow: "Is your question about programming?" - As I read this question, it's about programming (let us not discuss the difference between "programming" and "scripting" here), not about software or hardware. Commented Mar 25, 2016 at 15:09
  • 2
    The concept you are looking for is called array. See: this post Commented Mar 25, 2016 at 15:15
  • 1
    @Stephan fair enough, thanks for the correction; I'll try to do better in the future. Commented Mar 25, 2016 at 15:30

1 Answer 1

3

you don't need a file:

@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

If you need the colon, just add it at set drive[!i!]=%%a: (I removed it (as one of several methods) to get rid of the unusual wmic line endings)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.