I'm creating a simple command-line backup script to use robocopy to mirror "important" stuff to my NAS box. I would prefer not to rely on a hard-coded mapped drive letter for that NAS box. In the script I would like to map a temporary drive letter, copy the relevant files, and dispose of the mapped drive. I don't want to assume that if that drive letter is already mapped, that it's pointing to the place I expect. I also don't want to "assume" that some drive letter is available when I map the drive, thus the leading '*'.
net use * \\nasbox\sharename password /user:username /persistent:no
What's the proper way within my .bat script to extract that drive letter for use in subsequent commands? I was thinking that I could piece together some variant of "for"'s token-parsing, but I also suspect there must be an easier way than esoteric for-syntax.
C:\>net use * \\nasbox\sharename password /user:username /persistent:no Drive Z: is now connected to \\nasbox\sharename. The command completed successfully. C:\>
Once I have the mapped drive letter, I would like to follow up with commands along the lines of:
robocopy C:\path\to\important\stuff %NewDrive%\path\to\backup /MIR /Z