Link to home
Start Free TrialLog in
Avatar of alconlabs
alconlabs

asked on

Reference volume by label

Is there a way to reference a volume by label instead of drive letter in a Windows path specification? For example, if I have a D: drive labeled "MY_DRIVE", how would I specify the following folder using "MY_DRIVE" instead of "D:\"?

    D:\FolderName\FileName
Avatar of Timothy Bryant
Timothy Bryant
Flag of United States of America image

Yes, what I think you may be looking for is mountvol?

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mountvol.mspx?mfr=true

You can use it to mount volumes using a name., as long as it's not the drive you are booting from? You just need to get the GUID of the drive.

Find it here using regedit->
HKLM\System\MountedDevices

Avatar of alconlabs
alconlabs

ASKER

Well, I don't have ready access to the GUID, just the volume name. (I'm writing a script.)
Can you try the following command from a command prompt and see if it returns the drive letter you are looking for.  If it does then we can include this in your BAT file to get the drive letter that corresponds to the label name you know, and then you can use that drive letter for file processing.  Change "data" below to the volume label you know.

wmic logicaldisk where volumename='data' get name

~bp
I have one here for you:

http://scripts.dragon-it.co.uk/links/batch-find-drive-by-name

which I guess is whre Bill was leading?

If you are running the script FROM the drive you can get the path of the script too using %~0 which you can get the drive from with %~d0 etc. if that helps too.

Steve
@echo off 
set drive=
set lookfor=MY_DRIVE
for /f "tokens=1" %%a in ('WMIC logicaldisk where VolumeName^="%lookfor%" get caption') do set drive=%%a

if not "%drive%"=="" (
  echo Found drive at %drive%
) ELSE (
  echo No drive named %lookfor% found.  Logical drives are:
  WMIC logicaldisk get caption, volumename, description, size, freespace
)

Open in new window

Try this and see what results you get.  Ignore "Audio CD" as it is not a Volume Label.  If it reports the drive volume labels correctly, then the theory can be used in another batch file for whatever other purpose you would like.
Drive-Names.cmd
Billprew's solution fails to find the specified drive.

Dragon-it lists the drives and volumes correctly, but fails to find the specified drive.

BillDL's solution correctly lists the volume names and corresponding drive letters, but doesn't indicate whether a volume can be referenced directly by name instead of letter. My conclusion based on these answers is that it cannot.

Thanks
All of these approaches follow the same approach.  It is true that you cannot directly access folders and files on a disk purely based on the volume name.  You need to find out the drive letter that has been assigned, and that is what these approaches try to accomplish.

If you don't want to go down this path, getting the drive letter and then using that to access the drive, then none of these solutions will help.

~bp
agreed with bills coments there.  if you arent getting a drive back from my slution then please remove the echo off from the top and copy / paste the results here.

What are you trying to find?  the drive letter of a backup drive, usb key, the drive the batch is run from, or something else?

Steve
ASKER CERTIFIED SOLUTION
Avatar of BillDL
BillDL
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmmm. Some spoiling mistakes in there ("forst", "fole path").  I sound like Oi'm from Donegal, Oirland.  To keep the accent you could rename that last batch foil to "Foind-Flash-Droive.cmd" ;-)
to be sure.
I'm trying to write a batch file in WinPE 3.0 to deploy images on systems that come in various hardware configurations, including attached removable USB drives. The drive letter assignments vary, but the volume names are (somewhat) consistent. I'm not expert in writing batch files, so the idea was to find a way to reference volumes by name rather than letter. So the short answer is I can't do that directly, but there are alternatives (as described above).
I wonder why we bother sometimes....
Thank you alconlabs.
Bill, bill and dragon-it,
THANKS!!!!  I was looking for a solution to get the drive letter of a USB volume so I can run a program from a link in a CMH file.  

You guys Rock!!!

thanks again,
No problem, glad it helped.

Steve