Windows handles network paths as UNC (universal naming convention), and because they differ from the local file system naming convention you might often find programs that cannot handle those. You can somehow map network paths as virtual drives, but it can quickly become tedious and you have to redo the same mapping on all computers you use.

Hopefully Windows can do the mapping on request, for example if you directly open a command window inside a network folder… wait, how do you do that? Hold down the shift key, right click in explorer, and here comes the invaluable “Open Command Window Here” feature which will land you in a freshly mounted virtual drive (that you can also see in explorer). But every time you open a command window in such a way you will consume an available drive letter.

Now have you ever used PUSHD and POPD? The first one is like CD, but it keeps the previous directory on a stack so the other one can go back one step at a time. An additional benefit of PUSHD is it that it will map network drives as required so you can navigate UNC paths, but the icing on the cake is that POPD will release the mappings!

Did you know that you can drag&drop files and folders on a batch file to have it called with their full paths as parameters? It also has the side effect that the current directory should be the one containing the given files or folders, but UNC paths won’t work and you will end up in the Windows root directory. How could we use the PUSHD trick above in this context?

Time for some obfuscated syntax. When running a batch script, %0 is the full name of the script itself, %n is the nth parameter, and there are some “scanf-like” modifiers that can be used to extract information from those paths. One is %~dp0, which will return the drive (d) and path (p) from the script’s own full name. And now we can use PUSHD, store the mapping, then go back to the script folder.

pushd %~dp1%
set TEMP_FOLDER=%cd%
cd /D %~dp0%

The Internet is so full of batch hacks and tips that I thought that detailing one I find particularly useful would be of some help, would you mind sharing your favorite one?