Opening and Renaming Files

Anything Really. Just keep it clean!

Moderators: Dorian (MJT support), JRL

Post Reply
claremc
Newbie
Posts: 4
Joined: Thu Jan 23, 2020 8:55 pm

Opening and Renaming Files

Post by claremc » Thu Jan 23, 2020 9:12 pm

I am currently working to automate naming T4 and T5 documents for my company based on the Business Number of the cllient. As of right now they are very long names and can be automatically archived if they have the business name in the title. They all get sent to one folder so I need to be able to go through this folder and open then rename the files one at a time.

The code I have as it stands opens the PDF file, exports it to a word document, and then uses image recognition to copy the the BN to be able to save the PDF with this as the document name.

What I am struggling with is iterating through the files to automate opening them, as this process is going to need to work with a variable amount of files (some days there could be 1-20 files and other days there won't be any). I've seen examples on using GetFileList for similar situations but I'm unclear how it would work for my specific issue.

My other issue at the moment is the image recognition as I have used the code builder to do this and I noticed that it specifies the window name - which corresponds to the document name in this case. Are there work arounds for this to be able to run this process on different files?

The code for image recognition of the BN and copying it:

FindImagePos>%BMP_DIR%\image_7.bmp,WINDOW:T4_Client Name (Business Name).docx [Compatibility Mode] - Microsoft Office,0.7,3,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
MouseMove>XArr_0,YArr_0
LClick
Endif

Wait>2
Press Shift
Press Right * 9
Release Shift

Press CTRL
SendText>c
Release CTRL
Clare

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Opening and Renaming Files

Post by Dorian (MJT support) » Fri Jan 24, 2020 9:36 am

If you look at the help file for GetFileList, you'll see this example :

Code: Select all

GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%

Let>k=0
Repeat>k
  Let>k=k+1
  Message>file_names_%k%
Until>k,file_names_count
The "action" part of that sample would be Message>file_names_%k%. This is where you'd do something like this :

ExecuteFile>file_names_%k%
WaitWindowOpen>T4*
..then continue with your code.

You should be able to use a wild card for the window title in FindImagePos. So something along the lines of :

Code: Select all

FindImagePos>%BMP_DIR%\image_7.bmp,WINDOW:T4_*
One question though - why are we opening them in Word and using Image Recognition? Is that a necessary part of the process? If the BN is text, and is identifiable, I'd be more inclined to completely bypass Word and do something like this :

Get the file list > name
Use Macro Scheduler to run PDFtoText to extract text from the PDF
If it contains the BN, use CopyFile (and copy to a different location - safer for testing) or RenameFile
If it doesn't, do something else.

If you'd like to send us a sample PDF and tell us what you want to do in more detail, we'd be happy to get you started.
Yes, we have a Custom Scripting Service. Message me or go here

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