B. J. Torreano
B. J. Torreano

Reputation: 13

Batch OCR files in subfolders and save new files with new name

I have the following code, which OCR's all PDF files in a specific folder (d:\extracttmp2), but it does not rename the files as I would like, or put the new files in the right place.

Currently, all files are within subfolders of 'extracttmp2'.

The OCR runs correctly, but I would like the OCR'ed files to be renamed to: <parent folder path>-<filename>_ocred.pdf. Naming them in such a manner will produce no file overwrites.

Currently, the code OCR's the files, but it saves the new files to the folder above the folder they are located in. It also saves the filenames as "JAN_ocred.pdf", for example, for a file named "JAN.pdf". The result of saving up one folder leads to some file overwrites, which is unwanted.

Also, it doesn't matter if the OCR'ed files remain in the folder where the un-OCR'ed files are located, or if they're saved up one folder. The desired renaming will eliminate any overwrites.

The software I'm using is PDF24. https://creator.pdf24.org/manual/10/#command-line. However, I think that my problem is not with the OCR software, but my syntax in the batch script.

Can anyone tell me what I am doing wrong?

    For /R d:\extracttmp2\ %%G in (*.pdf) do "C:\Program Files\PDF24\pdf24-Ocr.exe" -outputFile "%%~nG_ocred.pdf" -language eng -dpi 300 -skipFilesWithText "%%G"

Upvotes: 0

Views: 1109

Answers (1)

Compo
Compo

Reputation: 38622

Is this what you mean? i.e. files will be saved in the same location as before, but each name will be prefixed with their parent directories' name, followed by a hyphen/dash.

@For /R "D:\extracttmp2" %%G In (*.pdf) Do @For %%H In ("%%~dpG.") Do @"%ProgramFiles%\PDF24\pdf24-Ocr.exe" -outputFile "%%~nxH-%%~nG_ocred%%~xG" -language eng -dpi 300 -skipFilesWithText "%%G"

Just a quick clarification: D:\extracttmp2\directory1\JAN.pdf would be saved in the working directory with the name directory1-JAN_ocred.pdf, and D:\extracttmp2\directory2\subdirectory3\SOMENAME.pdf, as subdirectory3-SOMENAME_ocred.pdf

If you want to save the files somewhere else, either change the working directory, or prepend it to %%~nxH-%%~nG_ocred%%~xG

Upvotes: 1

Related Questions