I use a CLI utility called tesseract-ocr. The tesseract-ocr's usage in the cmd is this: tesseract.exe imagename outputbase [options...] [configfile...] In my case I type: tesseract photo0043.jpg photo0043.txt -l Cyrillic The utility will take the file called photo0043.jpg and output its job into the file called photo0043.txt How to make a batch to run the utility on an entire directory recursively?


Use a .bat file with the FOR /R command to loop through files and recurse on subfolders.

Something like:

@echo off
Setlocal enabledelayedexpansion

For /R C:\path\to\folder %%a in (*.jpg) Do (
Set filename=%%~na
tesseract "%%a" !filename!.txt -l Cyrillic

Warning: I have not tested this script. It needs some tweaking if you have .jpg files in subfolders of the specified folder.

  • I've surrounded the folder path and %%~na with double quotes and it worked but not for .jpg files in subfolders. Also, how to make it so that the output files are created in the same location where input files are because when I ran the batch everything was created in the root folder that was specified. Feb 11 '19 at 21:26
  • You could add the target path in the script in front of !filename!.txt. Might need enclosing in double quotes.
    – harrymc
    Feb 12 '19 at 12:04
  • This does the job for me if anybody is interested.. @echo off Setlocal enabledelayedexpansion For /R "C:\path\to\folder" %%a in (*jpg) Do ( Set filename="%%~dpna" "tesseract" "%%a" !filename!.TESS -l Cyrillic ) Feb 13 '19 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.