Changing the filename of a snapz output file

Reader Nathan Casselton asked about using my program, snapz.exe (described in a previous post), to capture multiple images using a sequence of numbered filenames (e.g. '1.dib', '2.dib', '3.dib', etc.)

It is possible to do something like this without modifying the snapz application itself. It can simply be packaged up in a batch file as I show below. A good starting point is to show how snapz can be used to capture an image under a different filename than the default one ('snapz.dib'). To do this, use a command like the following:

snapz.exe & rename snapz.dib newfile.dib

This is really two commands in a single line. The first command is 'snapz.exe', which captures an image and stores it as 'snapz.dib'. The second command is 'rename snapz.dib newfile.dib', which renames the captured file as 'newfile.dib'. Naturally, you can use whatever filename you want here. The ampersand (that’s the ‘&’ symbol) is simply used to ensure that each of the two commands is interpreted in isolation, even though they share a single line.

Now that we can assign any filename we want to the images captured by snapz, it’s possible to wrap it up in a batch file that captures multiple images under numbered filenames using a DOS for loop. Here’s the batch file I’ve come up with:

FOR /L %%i IN (1,1,5) DO (
    rename snapz.dib %%i.dib
    sleep 1

To run this script, just save it as a '.bat' file (I called mine 'sequence.bat'), in the same directory as snapz.exe. To run the script, just type 'sequence'. My example captures five images to filenames numbered 1 to 5. If you wish to capture more (or less) images, just change the number ‘5’ in the first line. I’ve also included the command ‘sleep 1’ in the loop to create an extra one-second delay between snapshots. You can change the number ‘1’ to create a longer delay. Alternatively, to take the sequence of snapshots as quickly as possible, just remove the sleep line altogether.

This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

2 Responses to Changing the filename of a snapz output file

  1. Dude guy says:

    Well, this is quite the nifty program! When I do a google search this is just about the only thing I can find on “command line webcam capture”. And if you could incorporate custom arguments for the snapz.exe and some more bells and whistles for a paid one, than you sir are in for some money! I would buy it…

    Here is something similar that you should incorporate:


    • batchloaf says:

      Thanks for the suggestions Dude guy. I’m working on a new DirectShow version of this program, which should hopefully work with a wider range of cameras, and which will include several command line options. Unfortunately, it’s taking me a while to get it done because I’m working on a lot of other things and snapz is really just a little pet project. I have no plans to release it commercially, so I’ll probably just be posting it up here for free download. Anyway, thanks again for your comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s