SUBST

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

SUBST

#1 Post by Squashman » 07 Jan 2014 16:47

Not sure if this was ever covered but for some reason I thought about the SUBST command today. It had it uses back in the day. But I was intrigued by the undocumented behavior explained on the SS64 site.

Undocumented behaviour: if a drive is substed using characters other than A-Z ($,#, :, !, 0-9) it will not appear in Windows Explorer or in the drives reported by SUBST.

And sure enough it works.

Code: Select all

C:\>subst #: T:\

C:\>subst

C:\>#:

#:\>dir /a-d
 Volume in drive # is ListProcess
 Volume Serial Number is 9E06-E4C5

 Directory of #:\

09/23/2013  09:29 PM               596 Temp.txt

#:\>c:

C:\>subst #: /d

C:\>


Subst does work with Network shares as well so you can do this.

Code: Select all

subst #: \\servername\share


Should you ever for some reason be out of drive letters or not want to access a file directly with a UNC path then I guess you can have more than 26 drive letters with a CATCH! They don't show up in Windows Explorer so you have to know that they are there.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: SUBST

#2 Post by penpen » 07 Jan 2014 18:20

I'm not sure if that really is undocumented (except the : as a drive letter; this is undocumented, as it is an unallowed character for names).
I may be called unexpected, too (and then the documentation is only a little bit "hidden").
But maybe i assume this only because i seldomly use this, and haven't read the help page under windows (XP) in detail until now.
The allowed characters for a path name, path and namespace according to http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#paths are:
Microsoft: Naming Files, Paths, and Namespaces wrote:•Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

◦The following reserved characters:

■< (less than)
■> (greater than)
■: (colon)
■" (double quote)
■/ (forward slash)
■\ (backslash)
■| (vertical bar or pipe)
■? (question mark)
■* (asterisk)
◦Integer value zero, sometimes referred to as the ASCII NUL character.
◦Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
◦Any other character that the target file system does not allow.
A drive letter is, as the name says a letter, and i assume they meant the allowed letters only.

subst /? wrote:Associates a path with a drive letter.

SUBST [drive1: [drive2:]path]
SUBST drive1: /D

drive1: Specifies a virtual drive to which you want to assign a path.
[drive2:]path Specifies a physical drive and path you want to assign to
a virtual drive.
/D Deletes a substituted (virtual) drive.

Type SUBST with no parameters to display a list of current virtual drives.
As drive1 is specified to be a virtual drive, so it uses the Win32 File Namespaces ==> It supports UNC.
So (from this side of view) you have discovered a bug in the output of the the list of drives.
Actually i haven't decided on which side of view i want to stay, maybe another has more agrguments, or can weaken my above arguments.

penpen

Edit: If you may define the drive named double-colon, then you may not be able to change to as you would have to enter the Paamayim Nekudotayim, which is an invalid label making the command processor to ignore the complete line.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: SUBST

#3 Post by carlos » 07 Jan 2014 21:58

The A-Z link to a post with the info. The same behavior is in mountvol.exe

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: SUBST

#4 Post by dbenham » 07 Jan 2014 22:19

penpen wrote:If you may define the drive named double-colon, then you may not be able to change to as you would have to enter the Paamayim Nekudotayim, which is an invalid label making the command processor to ignore the complete line.

You can access :: by using PUSHD ::


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: SUBST

#5 Post by foxidrive » 07 Jan 2014 23:42

If anyone has the interest, do these work?

Code: Select all

if exist "::\" echo banana
if exist "#:\" echo apple

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: SUBST

#6 Post by dbenham » 08 Jan 2014 06:47

foxidrive wrote:If anyone has the interest, do these work?

Code: Select all

if exist "::\" echo banana
if exist "#:\" echo apple

Yes, they work.

Other ways to access ::

Code: Select all

for %%D in (::) do %%D

setlocal enableDelayedExpansion
set "drive=::"
!drive!


Dave Benham

Post Reply