Sunday, September 21, 2008

Make batch files that do different things at work and at home

The DOS/Windows batch file, one of my favorite tools. I worry that Kids Today won't learn how to use 'em, not like back in the dawn of the IBM PC, when I used to make menus for people using batch files. And they were grateful for them. Grateful, I tell you!

Here's something easy you can do with a batch file. Say you have a laptop you tote between work and home, and you have want to back up a file before you use it, but only when you're at the office. I say office, but any two computing environments might work. Use this trick to write a batch file that you use to launch the file...backing it up before launching it.

Use the batch IF command to create some behavior that only occurs in one of your environments.

IF keys off of the existence of a file or folder, so you need some distinction of that sort. But usually, you'll have access to some mapped drive letter in one environment that you won't have in the other.

So, write your commands like this

IF NOT EXIST X:\WORKFOLDER GOTO :NOTATWORK

xxx commands to be run when you're at work xxx

:NOTATWORK

1 comment: