Have you ever needed to temporarily map a drive letter to a network location for a quick file operation while you were working from a Command Prompt? Of course, you can switch over to Windows Explorer and use the Map Network Drive command. However, that requires multiple steps to create and then you have to perform several more steps to disconnect the network drive. This can be a pain, especially when you’re working from a Command Prompt. Fortunately, you can use a pair of often-overlooked Command Line tools still available in Microsoft Windows 7 — PushD and PopD — to quickly map network drives.
In this edition of the Windows Desktop Report, I’ll show you how to use PushD and PopD for temporary drive mapping. As I do, I’ll explain how these two old DOS utilities work.
This blog post is also available in the Slideshow Photo Gallery format.
The Map Network Drive command
Just for the sake of comparison, let’s begin by taking a look at all the steps involved in temporarily mapping a network drive in Windows Explorer. When you need to map a network drive from within Windows Explorer you can pull down the Tools menu and select the Map Network Drive command. If you are running Windows 7 with its context-sensitive Command Bar, when you open Computer, the Map Network Drive command will appear on the Command Bar, as shown in Figure A.
In Windows 7, the Map Network Drive command appears on the Command Bar.
When you see the Map Network Drive window, as shown in Figure B, you use the Drive drop-down to select a drive letter. Then, you can use the Folder drop-down to select a drive you’ve previously mapped or click the Browse button and use the Browse for Folder dialog box to locate the network folder that you want to map to a drive. Be sure to leave the Reconnect at Logon check box unselected.
If you have connected to the drive before, you can find the network path on the Folder drop-down.
When you are done using the drive, you must then return to Windows Explorer, pull down the Tools menu, and then select the Disconnect Network Drive command. When you see the Disconnect Network Drive dialog box, as shown in Figure C, just select the drive icon and click OK.
To disconnect, just select the icon and click OK.
As you can see, using Windows Explorer’s network drive mapping feature really isn’t that complex, but it does require a multitude of steps. This is especially apparent when you see how quickly the same operation can be performed using the PushD/PopD commands.
The PushD/PopD commands
As you may know, the PushD and PopD commands have been around since Windows 2000 and are powerful little commands that can save you quite a bit of time when you are working on the Command Prompt. However, they are often overlooked.
Basically, the PushD/PopD commands are used to maintain a history list of directory paths in what is called a directory stack. In addition, these commands function like the Change Directory (CD) command.
The syntax for the PushD command is:
When you use it, the PushD command stores the current path in the directory stack and then immediately changes to the specified path. When you use the PopD command, it retrieves the path at the top of the stack and changes to that path.
For example, if you are currently in the C:\Users\Greg\Documents directory and you type the command:
Then the C:\Users\Greg\Documents path is stored in the directory stack and the current directory becomes C:\Users\Public. When you are done working in the C:\Users\Public directory, you just type:
When you do, the C:\Users\Greg\Documents path is retrieved from the directory stack and the current directory becomes C:\Users\Greg\Documents. This example is shown in Figure D.
The PushD and PopD commands in action.
Mapping network drives
In addition to making it easy to change back and forth between directories, the PushD and PopD commands also work with network paths. When working with network paths, the syntax for the PushD command is:
Where \\Server\Share\path is the network resource to which you want to map a drive letter. As soon as you use it, the PushD command will instantly map a drive letter to the network resource and then change to that drive right in the Command Prompt window. When you’re done, just type PopD and the mapped drive letter will be disconnected and you’ll return to your original drive.
Keep in mind that the PushD command allocates drive letters from Z: on down and will use the first unused drive letter that it finds.
Figure E illustrates the same network mapping procedure that I showed you earlier in Windows Explorer.
Mapping a network drive with the PushD and PopD commands is a piece of cake.
What’s your take?
Have you used the PushD and PopD commands before? Have you ever had the need to set up a temporary drive map while working from the Command Prompt? Are you likely to use PushD and PopD commands to temporarily map a drive letter from the Command Prompt? As always, if you have comments or information to share about this topic, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.