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.

Donald Trump
  • 83
  • 1
  • 6
  • Somehow this feels more at home over at [SuperUser](http://superuser.com/) than here, but I may be wrong. – Shark Mar 25 '16 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) – Stephan Mar 25 '16 at 14:33
  • @Stephan there's no point in arguing anything in this case IMO, I get that we should stick to retaining users to our own respective communities, but on the other hand - we deal with code and programming while SuperUser generally deals with scripts and scripting. And this is a scripting question. Showing a failing script or not would not change much, it would still be a "failing script question". – Shark Mar 25 '16 at 14:58
  • 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. – Stephan Mar 25 '16 at 15:09
  • 2
    The concept you are looking for is called _array_. See: [this post](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Mar 25 '16 at 15:15
  • 1
    @Stephan fair enough, thanks for the correction; I'll try to do better in the future. – Shark Mar 25 '16 at 15:30

1 Answers1

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)

Stephan
  • 53,940
  • 10
  • 58
  • 91