SOLVED Problem using SET command in CMD file

Joined
May 16, 2017
Messages
8
Reaction score
0
I have a CMD file used to create backups from my C: drive to a user-designated USB drive. The fundamentals are working fine, but a small refinement I'd like to add is giving me a problem.

At the beginning of the CMD, I get the port where the USB device is located using the SET /p new_variable= construct: this works fine.

Say the name of this variable is M_drive1 (the drive letter).

Later I create another new_variable (to use in the XCOPY command that does the actual "backup"). That new_variable is created using this construct: SET M_outdrive=%M_drive1%:?

So if the user enters "m" (no quotes) to the request for drive letter, then M_drive1 contains the letter m, and M_outdrive contains m:\.

The CMD file then verifies that the named drive is valid (exists) and aborts if not.

All the above works as intended.

At this point I'd like to display the USB disk volume label. So I want to create a variable to pass to the Vol command. For that I use the command: SET M_vol=%M_drive1%:.

But that creates a variable M_vol that just contains the colon ... no drive letter.

Can someone tell me what I'm doing wrong?
 
Joined
May 16, 2017
Messages
8
Reaction score
0
I forgot to add: I'm running 64 bit Windows 7 Pro.
 
Last edited:
Joined
Jun 17, 2017
Messages
18
Reaction score
0
I think I know what you are trying to do, but explaining all in pure text seems to make it harder to understand. Can you just put the exact code, or similar code ?
 
Joined
May 16, 2017
Messages
8
Reaction score
0
I appreciate your offer to help.

As sometimes happens, when I was in the process of selecting the code to post here, I discovered the cause of the problem: I had used the wrong variable in the SET command.
And the underlying cause of that was mistaking the number "1" for a lower case "l". My bad, sorry.
Once I corrected the variable name, the SET command worked as I intended.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top