Apply recursion in a batch script

1

Some time ago, I had to use Microsoft Office Document Imaging to convert a document template created in Microsoft Word as an anti-copy prevention measure for the template itself (positioning, , settings, and so on.)

But the application in question, for those who do not know, is very spartan, slow, and with too many weird restrictions on a GUI . Fortunately, the functionality I needed from it, could be run on the command line.

I've never been very much a fan of batch scripts, but I've even chosen to create a .BAT file to automate the OCR of MDI files previously generated by the virtual printer provided by the application.

Since the syntax of batch scripts was already old when I got my first computer, I never bothered to learn more than I needed to install Windows 98 (at the time) and I ended up with the following file:

@echo off

set filesCount=0

echo Performing OCR over files
echo.

for /r %%i in (*.mdi) do (

set /a filesCount+=1

echo Curent file: %%i

"C:\Program Files\Common Files\Microsoft Shared\MODI.0\MSPVIEW.EXE" -f %%i

echo OCR performed succesfully
echo.

)

echo.
echo OCR performed over %filesCount% files found
echo.

pause

It works fine, but I have to duplicate (or move) the .BAT file to each directory before running it. And as the execution is applied to thousands of files structured hierarchically in several sub-levels, this becomes a tedious task almost and does not make it worth using the script.

Is it possible to modify this script so that it operates recursively? That way, I'd store it in the parent directory of all sub-levels and run it once.

    
asked by anonymous 08.08.2014 / 22:36

1 answer

2

According to a test I performed here, your bat already works recursively:

test.bat

@echo off

set filesCount=0

echo Performing OCR over files
echo.

for /r %%i in (*.mdi) do (

set /a filesCount+=1

echo Curent file: %%i


echo OCR performed succesfully
echo.

)

echo.
echo OCR performed over %filesCount% files found
echo.

pause

result:

Note:line"C:\Program Files\Common Files\Microsoft Shared\MODI.0\MSPVIEW.EXE" -f %%i has been removed to avoid errors during execution, as I do not have this executable.

    
09.08.2014 / 01:30