Cooking with DOS

The Windows command line scares most people but if you want to automate stuff then command line scripts can be your best friend. In this series of posts I’ll be taking you through many of the processes involved with digitisation and looking at how they can be performed with freely available utilities.Before we get into our first scripts you might¬†want to go and get the tools that we’ll be using if you don’t already have them…

Batch files are nothing more than plain text files with a file extension of “.bat” instead of “.txt”. They are essentially a list of instructions that tell your computer to do stuff, saving you the effort of typing each command into a command prompt window.

I won’t be teaching you how to write command line batch files from scratch. Instead I’ll be using some of the scripts that I already use and explain their usage so that you can modify them for your own purposes.¬† The scripts will be presented as code. Comments are included using lines starting with “REM”. Optional bits for input and output files will be italicised. e.g.

REM This is a comment
"c:\tools\tool_A.exe" -a -b "InputFile" "OutputFile"
REM You can remove comments to speed up operation

Batch file categories

There are a number of ways that you can run a script in Windows and which one you use will depend on what your are trying to achieve and how much automation you want.

Edit and Run

BAT files are just plain text files with a file extension of “.bat” so you can edit them in any text editor. Simply edit them first and then double click on them to run. This is OK for testing but it’s not a very productive way to work… unless of course you get a database or spreadsheet to do all of the work creating the batch file.

Drag and drop

Dragging and dropping a file (or folder) onto a batch file is the equivalent of running the batch file from the command line with the name of the file afterwards. eg.

"c:\tools\tool.exe" "myfile"

The name of the file is passed to the batch file as a variable, which has the advantage of being able to reuse parts of the file name in the script.

Send to

Using the “Send to” menu to send a file or folder to a batch file is effectively the same as using drag and drop with the added advantage of not having to drag the file between windows. All you have to do is right click on a file and find your script in the “Send to” submenu that pops up. Use it sparingly though, or you menu will become bloated and difficult to use. Any script categorised as drag and drop can be used in this way as well.

An appetiser

So let’s start of small with a script that I do have in my “Send to” menu… reading metadata from a file. It’s pretty hard to convince people to embed metadata in files when so much of it is often hidden away. This simple script reads all of the available metadata in a file and displays the result in your text editor.

Script: read_file_metadata.bat

Category: Drag and drop (file)


"c:\tools\EXIFTool\EXIFTool.exe" -s -a -g -u %1 > "c:\temp\metadata.txt"

Breakdown: This script runs EXIFTool.exe to read the metadata from the file dragged onto it (%1) including any unidentified tags (-u) and duplicate tags (-a), displaying short tag names (-s) and grouping the output by tag groups (-g), writing the results to a text file (> c:\temp\metadata.txt). This text file is then opened so that you can see the result. I use a text file rather than the pause option for EXIFTool because it’s easier to copy text from the metadata if required.

My next post in Cooking with DOS will look at both reading and writing metadata with EXIFTool.


If you’re looking to learn more about writing CMD scripts, here are some of the reference material that I commonly refer to:

Leave a Reply

Your email address will not be published. Required fields are marked *