1

I want to list all windows partitions and then exclude partition in which window is installed like (C:\ , it can be any letter) here is command to list partitions

for /f "skip=1 delims=" %x in ('wmic logicaldisk get caption') do @echo.%x

output:

D:
E:
C:
M:
X:
Y:

and here is command to find partition in which windows is installed

for /f "tokens=1 delims=\" %i in ('echo %userprofile%') do @echo %i

output:

C:

is there any for loop command to list all partitions excluding windows partition and can output like this

D:
E:
M:
X:
Y:
1
  • 1
    User profiles can be on a different drive than the system.  If you want to know where Windows is installed, it may be better to use%SystemRoot% (or %SystemDrive%) rather than %UserProfile%). Feb 13, 2021 at 8:20

2 Answers 2

2

You can avoid Caption, %SystemDrive% and additional extra spaces after every letter using ^|findstr/v "Cap %SystemDrive%" in your loop command, and remove Skip=1 Delims=:

for /f %i in ('wmic logicaldisk get caption^|findstr/v "Cap %SystemDrive%"')do @echo\%i
3
  • This seems to perform quicker than the other answer in my testing. Feb 11, 2021 at 2:39
  • @DrinkSomePimpJuiceIT Thanks for your comment. It is slower takes a look here look here
    – Io-oI
    Feb 11, 2021 at 11:00
  • I don't see the whole command in that screen shot but for my system without the actual time measuring tool on my system, the command you provided appears to show all the multiple drive letters a little quicker than the other answer. It is most certainly quicker than the below command in my system that I can tell for the entire command to process all drives. Feb 11, 2021 at 13:03
3
for /f "skip=1 delims=" %x in ('wmic logicaldisk get caption') do @echo.%x | find /v "%userprofile:~0,2%"
3
  • for /f "skip=1 delims=" %x in ('wmic logicaldisk get caption') do @echo.%x | find /v "%userprofile:~0,2%" >> output.txt there is some extra spaces after every letter can we remove??
    – Sadam
    Feb 10, 2021 at 6:17
  • 1
    @Sadam - In the delims part you are selecting the whole line from WMIC which has trailing spaces. Change it to this "skip=1 delims= " Feb 11, 2021 at 7:19
  • Or just leave off the delims= option altogether. Feb 13, 2021 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .