look for volume name, change drive letter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
EricM
Posts: 4
Joined: 11 May 2015 13:00

look for volume name, change drive letter

#1 Post by EricM » 11 May 2015 13:12

I am currently learning how to do batch scripting. Would I like to do is make a batch file that looks for the volume name of a drive and then once it find its renames the drive letter to another letter.

Example

Plug in usb drive: OMG (E:)
Script finds volume label OMG
Renames (E:) to (O:)
End results is

OMG (O:)

I would like this to work somehow, because I am going to be using it to set up multi computers at once. I am just trying to make the install process a bit smoother on things.

Thanks

Eric

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: look for volume name, change drive letter

#2 Post by Squashman » 11 May 2015 13:40

You may not even need to do that at all. I would rather you explain what you are trying because there may be a better way to do it.

EricM
Posts: 4
Joined: 11 May 2015 13:00

Re: look for volume name, change drive letter

#3 Post by EricM » 11 May 2015 14:29

What I would like to do is Move a certain file, well its a VPN connection file. So in the script I would like the file be moved from the USB with a copy and paste command. so from O:\rasphone.pbk copy file from file path to. C:\Users\OMG\AppData\Roaming\Microsoft\Network\Connections\Pbk

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: look for volume name, change drive letter

#4 Post by aGerman » 11 May 2015 16:28

You however have to find the drive letter of you USB device first. Once you know it the changing of the letter would be pointless.

Untested:

Code: Select all

@echo off &setlocal
for /f "tokens=1* delims==" %%i in (
  'wmic logicaldisk where "VolumeName='OMG'" get DeviceID /value'
) do for /f %%k in ("%%j") do set "drive=%%k"
ECHO copy /y "%drive%\rasphone.pbk" "%appdata%\Microsoft\Network\Connections\Pbk\"
PAUSE

Remove ECHO and PAUSE if drive letter and path are displayed correctly.

Regards
aGerman

EricM
Posts: 4
Joined: 11 May 2015 13:00

Re: look for volume name, change drive letter

#5 Post by EricM » 12 May 2015 06:28

I will give it shot in a little bit here today and let you know the results of this.

Thanks in advance

*EDIT*

I tested the above code and it shows the drive and the location correctly. It just doesn't copy/paste the the file in the folder location.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: look for volume name, change drive letter

#6 Post by aGerman » 12 May 2015 11:49

aGerman wrote:Remove ECHO and PAUSE if drive letter and path are displayed correctly.

:wink:

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: look for volume name, change drive letter

#7 Post by Squashman » 12 May 2015 12:04

aGerman wrote:
aGerman wrote:Remove ECHO and PAUSE if drive letter and path are displayed correctly.

:wink:

Reading is FUN!

EricM
Posts: 4
Joined: 11 May 2015 13:00

Re: look for volume name, change drive letter

#8 Post by EricM » 12 May 2015 12:18

Squashman wrote:Reading is FUN!


I didn't know echo and pause would cause it to stop it from copying over. Like I said before, I am learning on how to do this. sorry for not understand how it all works. :?

Post Reply