PUSHD reminder - it automatically maps network drives
I've blogged a few times about how cool PUSHD (and POPD) is from the cmd.exe prompt. It's one of the most powerful "DOS" commands that few folks use.
PUSHD, of course, maintains a stack of where you are in your file system. It will PUSH a directory on the stack and move you there automatically. Combined with a PROMPT variable that includes (somewhere) a $+, you'll get a very powerful way to move about.
Example from CMD>EXE:
C:\Documents and Settings\Scott>PUSHD c:\windows
C:\WINDOWS+>pushd system32
C:\WINDOWS\system32++>popd
C:\WINDOWS+>popd
C:\Documents and Settings\Scott>
One thing that I don't see a lot is PUSHD with UNC Paths, and how it will automatically map a drive for you, starting at Z: moving backwrads and will unmap them when you POPD.
Example from CMD.EXE:
C:\Documents and Settings\Scott>PUSHD \\SCOTTPC\D
Z:\+>PUSHD \\SCOTTPC\DESKTOP
Y:\++>POPD
Z:\+>POPD
C:\Documents and Settings\Scott>cd \\scottpc\desktop
'\\scottpc\desktop'
CMD does not support UNC paths as current directories.
But, of course, I can't CD to a UNC path with CMD.EXE.
However, all these scenarios, plus CD'ing to UNC paths work within Powershell:
PS C:\Documents and Settings\Scott> pushd \\scottpc\desktop
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\desktop> cd \\scottpc\d
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\d> cd \\scottpc\desktop
PS Microsoft.PowerShell.Core\FileSystem::\\scottpc\desktop> c:
PS C:\Documents and Settings\Scott> PUSHD \\SCOTTPC\D
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\D> PUSHD \\SCOTTPC\DESKTOP
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\DESKTOP> POPD
PS Microsoft.PowerShell.Core\FileSystem::\\SCOTTPC\D> POPD
PS C:\Documents and Settings\Scott> cd \\SCOTTPC\DESKTOP
Nice stuff to know. Thanks to Ryan Carr for the reminder.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Comments are closed.