I want to
cd to USB without specifying it because it changes its letter on every other computer.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
I'm going to assume you are asking how to use "cd" using a volume label rather than a drive letter.
The trick is to query WMI to get the drive letter from a given label, save the result to a variable, and the pushd that variable path.
@ECHO OFF FOR /F "tokens=1 skip=1" %%A IN ('WMIC logicaldisk where "volumename="%1"" get name') DO ( pushd %%A goto fileend ) :fileend
After the first result returned from WMIC, the loop will exit (Although, only one path should be returned anyways).
To use the script, save it as something like "cdlabel.cmd" anywhere in the PATH like System32, or in a easy-to-reach location. Then call it with the volume name as an argument like the following: "cdlabel GamingDrive"