Running a process on each file in a directory

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
hgupta1
Newbie
Posts: 3
Joined: Wed Jul 04, 2007 5:54 am
Contact:

Running a process on each file in a directory

Post by hgupta1 » Sat Aug 02, 2008 2:44 pm

I want to write a script that will run my OCR software on each PDF file in a folder and its subfolders. I want it to check for new files every night.

My OCR software is fairly automatic in that it will accept a filename as an argument, then it will process that file, append "_OCR" to the filename, and exit.

How can I write a macro that will look for PDFs without OCR in the name, and then run the program on them?

Thanks!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Aug 02, 2008 4:36 pm

Something like this perhaps:

Code: Select all

Let>RP_WAIT=1
//get a list of pdf files in the folder
GetFileList>c:\somedir\*.pdf,file_list

//Explode that list into an array
Separate>file_list,;,files

//Loop through the array
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_file=files_%k%

  //Only process this file if "OCR" is NOT in the filename

  //These two lines get the filename part from the end of the full path
  Separate>this_file,/,file_parts
  Let>filename=file_parts_%file_parts_count%

  //This returns the position of OCR in the filename, 0 if no match, in p
  Pos>OCR,filename,1,p
  If>p=0
    //So OCR did not appear in filename, so run your software passing the file to it
    Run>"YourOCRSoftware.exe" %this_file%
  Endif
Until>k=files_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hgupta1
Newbie
Posts: 3
Joined: Wed Jul 04, 2007 5:54 am
Contact:

Post by hgupta1 » Mon Aug 04, 2008 4:22 am

I really appreciate your help.


I think I am really close, however my OCR program isn't accepting arguments through macro scheduler very well.

I tried just the line "run>c:\ocrprogram.exe c:\testfile" on a sample file, and it wouldn't work.

But at a DOS command prompt, it will work.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Aug 04, 2008 5:31 am

You may need:

run>"c:\ocrprogram.exe" "c:\testfile"

But show me the DOS line.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts