Mostly Revit... by Eric Stimmel

pushd and popd

Thursday, April 18, 2013

Here’s a quick one that’s more of a Windows tip than a Revit tip, but it can come in handy to someone who manages files on network drives that aren’t always mapped to a drive letter. For example, when you need to get a quick list of files from a network folder.

I learned this from a Superuser forum response, but you can find more information on Wikipedia or just a quick Google search.

The scenario is simple, I’m in Windows Explorer looking at a folder of files and I want to email that list of files to someone so they can comment on it. I could take a screenshot, but I’d rather have text. Normally I would open the command prompt, cd to the location and type the following:

C:\path\to\files> dir /b > list.txt

This would list the files and folders (that’s the ‘/b’ part) and write that to a text file named list.txt which I could then open and manipulate. This doesn’t work on a UNC path. Windows tells you “CMD does not support UNC paths as current directories.” However with this newly discovered pushd command, I can do the following:

C:\path\to\files> pushd \\server\uncpath\to\files
X:\uncpath\to\files> dir /b > list.txt
X:\uncpath\to\files> popd
C:\path\to\files>

As you can see, the first command pushd takes the UNC path and temporarily maps it to a drive letter where I can operate on it as a local path. The second command popd deletes the temporary drive and returns you to where you were. Simple.