Cmd, use variables in conjunction with path completion.

Neutrino

New member
Local time
11:58 PM
Messages
5
Subject says it all really. If I use an environment variable on the commandline in a path it apppears to stop path completion from working correctly. In the example below on the last line I hit TAB after typing "dir %userprofile%\do" and instead of the path completion acting on the expanded %userprofile% variable and coming up with Documents it instead just retrieved the first hit for "do" from the root (current) directory.

Is there a fix or workaround for this as the inability to use environment variables and path completion together is really annoying?

Code:
C:\>echo %userprofile%
C:\Users\MyName

C:\>dir %userprofile%
 Volume in drive C has no label.
 Volume Serial Number is ACA3-CBF7

 Directory of C:\Users\MyName

06/08/2010  12:39    <DIR>          .
06/08/2010  12:39    <DIR>          ..
01/07/2010  09:27    <DIR>          Contacts
06/08/2010  15:09    <DIR>          Desktop
07/08/2010  10:45    <DIR>          Documents
07/08/2010  10:48    <DIR>          Downloads
01/07/2010  09:27    <DIR>          Favorites
01/07/2010  09:27    <DIR>          Links
07/08/2010  10:46    <DIR>          Music
07/08/2010  10:46    <DIR>          Pictures
01/07/2010  09:27    <DIR>          Searches
07/08/2010  10:46    <DIR>          Videos
               1 File(s)             85 bytes
              16 Dir(s)  43,400,957,952 bytes free

C:\>dir %userprofile%"\Documents and Settings"
 

My Computer

OS
Win7 Pro
Subject says it all really. If I use an environment variable on the commandline in a path it apppears to stop path completion from working correctly. In the example below on the last line I hit TAB after typing "dir %userprofile%\do" and instead of the path completion acting on the expanded %userprofile% variable and coming up with Documents it instead just retrieved the first hit for "do" from the root (current) directory.

Is there a fix or workaround for this as the inability to use environment variables and path completion together is really annoying?

Code:
C:\>echo %userprofile%
C:\Users\MyName
 
C:\>dir %userprofile%
 Volume in drive C has no label.
 Volume Serial Number is ACA3-CBF7
 
 Directory of C:\Users\MyName
 
06/08/2010  12:39    <DIR>          .
06/08/2010  12:39    <DIR>          ..
01/07/2010  09:27    <DIR>          Contacts
06/08/2010  15:09    <DIR>          Desktop
07/08/2010  10:45    <DIR>          Documents
07/08/2010  10:48    <DIR>          Downloads
01/07/2010  09:27    <DIR>          Favorites
01/07/2010  09:27    <DIR>          Links
07/08/2010  10:46    <DIR>          Music
07/08/2010  10:46    <DIR>          Pictures
01/07/2010  09:27    <DIR>          Searches
07/08/2010  10:46    <DIR>          Videos
               1 File(s)             85 bytes
              16 Dir(s)  43,400,957,952 bytes free
 
C:\>dir %userprofile%"\Documents and Settings"

The reason why you get "Document and Settings" when you press <TAB> to activate code completion is because you're in the root of the drive. I've just tested this, and got two different results. I highlighted what I typed before pressing <TAB>:
Code:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Peter Dzomlija>[B][U]dir Do[/U][/B]cuments
 Volume in drive C has no label.
 Volume Serial Number is 365F-53AD
 Directory of C:\Users\Peter Dzomlija\Documents
07/08/2010  08:10    <DIR>          My PSP Files
               0 File(s)              0 bytes
               1 Dir(s)  22,641,709,056 bytes free
C:\Users\Peter Dzomlija>cd\
C:\>[U][B]dir[/B] [/U]"[B][U]Do[/U][/B]cuments and Settings"
 Volume in drive C has no label.
 Volume Serial Number is 365F-53AD
 Directory of C:\Documents and Settings
File Not Found
C:\>

Code completion works on the current contents of a folder only, and does not reparse subfolders, nor does it expand environment variables. The EV expansion only comes into play when the command/s is executed.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Virtual Machine
OS
Windows 7 Professional 32-bit SP1
CPU
AMD A4/A6
Motherboard
Intel Corporation 440BX Desktop Reference Platform
Memory
3.00GB EDO
Graphics Card(s)
VMware SVGA 3D
Sound Card
High Definition Audio Device
Monitor(s) Displays
Generic Non-PnP Monitor on VMware SVGA 3D
Screen Resolution
1440x900
Hard Drives
1 x 60GB VMware Virtual SATA Hard Drive ATA Device
Antivirus
Kaspersky Total Security
If you enter a multipart path like:

c:\>dir \Users\

and then press TAB on my system the path completion does in fact correctly list the contents of any subdirectories the path links to, so it doesn't just work on the contents of the current directory.

The only problem is that the environment variables are not expanded into the path when this lookup process occurs, and since I assume the path lookup is performed by the command processor itself (cmd.exe) rather that any invoked command that seems like choice of behaviour that's neither intuitive nor useful.
 

My Computer

OS
Win7 Pro
Back
Top