Jump to content

Get Disk Number From Drive Letter In CMD


Recommended Posts


Be my guest :yes::

@echo offecho This cmd has been run from LogicalDrive %~d0\SET message=FOR /F "tokens=3,6 delims=#,=" %%A IN ('WMIC Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent') DO CALL :isitapartition %%B %%AIF NOT DEFINED message (ECHO You are either dencorso or someone else trying to make a oneliner senselesslyECHO complex without any meaningful reasonECHO Drive letter %~d0\ is NOT assigned to a partition on a disk.) ELSE (echo %message%)pauseGOTO :EOF:isitapartitionIF %1=="%~d0" SET message=LogicalDrive %~d0\ is residing on \\.\Physicaldrive%2GOTO :EOF

jaclaz

Link to comment
Share on other sites

And now this is a shorter version ;) (still taking into account use on a non-partition):

@echo offecho This cmd has been run from LogicalDrive %~d0\FOR /F "tokens=2 delims=#," %%? IN ('WMIC Path Win32_LogicalDiskToPartition Get Antecedent^, Dependent ^|FIND "%~d0"') DO (ECHO LogicalDrive %~d0\ is residing on \\.\Physicaldrive%%? && GOTO :done)ECHO Drive letter %~d0\ is NOT assigned to a partition on a disk.:donepause

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...