Delete a file based on the existence of another file

January 11, 2012 at 12:06:02
Specs: Windows 7
I am running OCR on PDF documents as part of a workflow, but Adobe has no way to delete the source documents. I was wondering if any of you know how I might check for the existence of a file matching <filename>OCR and delete the file matching <filename>.

Thus, I have two files in a folder.
File 1: A.pdf
File 2: AOCR.pdf

I want to check that AOCR.pdf exists and delete A.pdf in response. Since I don't know the names of the files ahead of time, I think the script needs to find the name by searching for the string OCR.pdf in a filename and then cut out the OCR to find the original file.

Would much prefer to use a batch script.

Thanks, I appreciate any and all help!


See More: Delete a file based on the existence of another file

Report •

#1
January 11, 2012 at 18:52:25
I think I figured it out by delimiting the OCR with - when renaming

FOR /f "tokens=1-3 delims=-" %%a IN ('dir /b/a-d C:\Test\*-OCR-.pdf') DO DEL /F/Q "C:\Test\%%a%%c"

Is this the best way to do it?


Report •
Related Solutions


Ask Question