0

I have a batch file on Windows cmd that uses zbar to read barcode value in an image file and renames the image file with the barcode value. It works fine on a single image file when it is called with a specific image file name. Say the image file is "image.tif" and the batch file is "zbar.bat". I call "zbar.bat image.tif" and the "image.tif" is renamed with the barcode value contained in the image. But I have dozens of images to rename - each containing different barcode value. I would like to call the batch file on many image files in a folder so each file is renamed with the barcode value of a given image.

Here's the batch file derived from https://blog.jamesbayley.com/2016/05/04/extract-a-barcode-from-an-image-and-rename-the-file/

REM (c 2016)James Bayley, MIT Licence (so you can use it freely)
REM Example of use extract-barcode-rename-file.bat image-with-barcode.jpg
ECHO off
REM Barcode labels can be printed using Avery Online Design and Print or
REM from Word or Excel using a free barcode font https://www.barcodesinc.com/free-barcode-font/
REM zbarimg from http://zbar.sourceforge.net/download.html
REM capture command output http://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file
REM substring http://stackoverflow.com/questions/636381/what-is-the-best-way-to-do-a-substring-in-a-batch-file

FOR /F "tokens=* USEBACKQ" %%F IN (`zbarimg -D -q %1`) DO (
 SET fullbarcode=%%F
    )
ECHO Full barcode: %fullbarcode%
ECHO ON
rename %1 %fullbarcode%.tif

Calling "zbar.bat *.tif" doesn't work. I'm wondering if there's a way to do that on multiple files. Say I have a folder with image files: 000000687.tif 000000688.tif 000000689.tif etc... Is there any way to process all the image files with the batch file so each image file is renamed?

Serpico
  • 11
  • After further research I've found the solution. To call the batch script on many files in a folder (assuming the batch file is named “zbar.bat” and we are processing “.tif” files) we simply call the following command in cmd window: for /f “tokens=*” %a in (‘dir /b *.tif’) do zbar.bat %a I hope it helps anybody who stumbles upon the same problem. – Serpico Sep 24 '16 at 18:36
  • 2
    you can answer your question as a question and mark it as well. This would help more than writing it in the comments :) – geisterfurz007 Sep 24 '16 at 22:56

0 Answers0