Posts by Fabrice Lété
  1. Books about people ( Counting comments... )
  2. Explanations come later ( Counting comments... )
  3. Programming for non programmers ( Counting comments... )
  4. I never managed to go left on first try. ( Counting comments... )
  5. code completion, a blessing and a curse ( Counting comments... )
  6. Poll, don't push ( Counting comments... )
  7. Starting the next project by hacking the old one ( Counting comments... )
  8. Let's hack on 34 year old code ( Counting comments... )
  9. A thirst for low-level programming ( Counting comments... )
  10. Stick Motion ( Counting comments... )
  11. #define-based architecture: design for inflexibility ( Counting comments... )
  12. Bugs for gourmets ( Counting comments... )
  13. A quick UNC path trick ( Counting comments... )
  14. Sorry but the game does not build anymore ( Counting comments... )
  15. Being terrible at making choices ( Counting comments... )
  16. The Sunk Cost Fallacy ( Counting comments... )
  17. What board games do better ( Counting comments... )
  18. Arguments of piracy ( Counting comments... )
  19. Lua elevator pitch (for very high buildings) ( Counting comments... )
  20. Teaching video games programming ( Counting comments... )
  21. The ill-fated BINAC ( Counting comments... )

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?