Related

Post navigation

5 thoughts on “Extract a barcode from an image and rename the file”

1. First it asks to specify which file is to be processed. Take a look:http://imageshack.com/i/poF8McDMp
I tried to modify the line
zbarimg -D -q %1
to
zbarimg -D -q %1 *.tif

2. After this it succesfully finds barcode but fails to rename the file. It seems that %1 paramteter is not indicating properly the original filename that is supposed to be renamed.http://imageshack.com/i/plbChoFfp

Dear David, From your screenshots it appears that you are callingzbar.bat
You have not included the file name. If your file is called myImage.tif then the correct statement would be,zbar.bat myImage.tif
In a batch file %1 means “the first parameter after the batch file name”. You can see another example of how to use the program on the first line of the batch file.
James

Hi James, thank you for the reply. Your advice worked. However the bat script works only for a single file. Is there a way to process many files in a folder? If I call zbar.bat on another file it erroneously calculate the “digits only” parameter (from the previous file). See screen below. I tried to call “zbar.bat *.tiff” as well but I get simillar error that file name is repeated or incorrect. My goal is to rename many files in a folder with barcodes numbers in each file as I have many dozens of files to rename every day.http://imageshack.com/i/powSLIj2p

After further research I’ve found a way to process many files in a folder. I removed the “digits only” function from the script so the rename command is “rename %1 %fullbarcode%.tif” and added “–raw” option to zbar command to get rid of barcode type value. After this modifications to run 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. Anyway, thank you for sharing the script – it is really helpful and makes my daily toil at work less tedious 🙂