Saturday, August 18, 2018

How to return the letters of all partitions on a drive in CMD/Batch?

My goal is to retrieve the letters of every partition and loop through those to complete another task on each partition using that letter as a variable. Currently right now I have...

wmic logicaldisk get caption

which returns...

Caption  
C:       
D:       

Now how do I take that output, and take only C, then D, as a variable for a batch script?

Thank you very much, appreciate the help.

Solved

Probable code example:

@Echo Off
For /F "Skip=1 Delims=:" %%A In ('WMIC LogicalDisk Get Caption') Do Echo=%%A:
Timeout -1

Change Echo= to an appropriate command as necessary.


No comments:

Post a Comment