Rename File Trouble

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Rename File Trouble

Post by CGooley » Wed Jul 03, 2019 2:57 pm

Hi,

Having trouble using rename file, for some reason this code below does not appear to work. (The file is still named the same)

Any help you may be able to offer is greatly appreciated. Results from code at bottom:

CF Result = True, CF Result Code= 123, message>file =S:\Accounting\Confidential\@Scaninbox\doc139781.pdf, message>newfile= S:\Accounting\Confidential\@Scaninbox\newname.pdf




//Open ScanInbox Folder given path
RunProgram>Explorer.exe S:\Accounting\Confidential\@Scaninbox

//Prepare to Rename the files
Label>StartRename

GetOldestFile>S:\Accounting\Confidential\@Scaninbox\*.pdf,file

ExecuteFile>file

WaitWindowOpen>Adobe Acrobat Pro*

//Get Company Name
OCRArea>1381,201,1782,218,company

//Get Check#
OCRArea>1972,314,2018,332,ck

//Get Amount
OCRArea>2336,306,2486,336,amount

//Close Adobe

setfocus>Adobe Acrobat Pro*
GetActiveWindow>window_title,X,Y
Separate>window_title,.,parts

//Close Adobe
CloseWindow>window_title

//Renaming in Scaninbox

Let>newfile=S:\Accounting\Confidential\@Scaninbox\Ck %ck%, %amount%.pdf


RenameFile>file,newfile

Message>CF_Result

Message>CF_RESULT_Code

Message>file

Message>newfile

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Wed Jul 03, 2019 3:47 pm

I think it may have something to do with a dollar sign in amount?

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Wed Jul 03, 2019 4:16 pm

Nope, it has to do with OCRArea, and the value stored in this variable. For some reason, the rename file function will not pass the values of these variables.

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Wed Jul 03, 2019 4:17 pm

Any ideas? GetTextInRect>left,top,right,bottom,result_variable does not work, and i'm using adobe.

User avatar
PepsiHog
Automation Wizard
Posts: 393
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Rename File Trouble

Post by PepsiHog » Wed Jul 03, 2019 6:20 pm

Use a vbscript. Sorry I don't currently have one to share. But if you search for vbs renaming script on the internet you will likely find one easily.

I have had the same exact issue. But that script was put on the back burner. But I have been thinking to return to it soon. My solution being vbs.

You may find it easy to do if you refer to my recent 'movefile' post. As I had issues that were resolved and may make it easy for you to get the rename vbs to work as desired.

PepsiHog
MS v14 Windows 10

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2018) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Wed Jul 03, 2019 6:50 pm

Thanks!

As an update, I found it has something to do with OCR area, and that I can clean the string by sending it to the clipboard, pasting into a search bar, and then copying that and getting the string off the clipboard.

There has to be an easy way to do this? I assume there's some format function I cant find? Very new to MS, so I appreciate your help here. I'll take a look at VB scripts as well.

User avatar
JRL
Automation Wizard
Posts: 3262
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Rename File Trouble

Post by JRL » Wed Jul 03, 2019 9:46 pm

Here is a sample of one way to filter out unwanted characters. This example removes tab and Carriage Return Line Feed from the string.

Edit:
Replaced a missing left bracket at the end of the "coded" script below.

Code: Select all

//Sample string with most typeable special characters
Let>vStr=~` !1@2+#3$4%crlf%5^6&7*8(9)0_aBc_Fg-+={[}]|\:;"'<,>.?/

//Splits string into components
RegEx>.,vStr,0,var,var_count,0

Let>vStrN=
Let>cc=0
Repeat>cc
  Add>cc,1
  Let>value=var_%cc%
  
  //Special allowance for double quote
  If>value="
    Goto>AddAnyway
  EndIf
  
  //Special removal for CR and LF
  If>{(%value%=%cr%)or(%value%=%lf%)}
    Goto>Remove
  EndIf
  
  //Convert character to its ASCII Number
  VBEval>ascW("%value%"),vAsc
  
  //The filter.  Keep Char if in range
  If>{(%vAsc%>31)and(%vAsc%<127)}
  
  Label>AddAnyway
    Let>vStrN=%vStrN%%value%
  EndIf
  Label>Remove
Until>cc=var_count

Let>msg_width=500
MdL>vStrN

User avatar
PepsiHog
Automation Wizard
Posts: 393
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Rename File Trouble

Post by PepsiHog » Fri Jul 05, 2019 3:43 am

@CGooley,
Happy Scripting!

VB Script to rename a file.

Code: Select all

VBStart
Option Explicit
Sub MoveFile(Source,Dest)
dim filesys
 set filesys=CreateObject("Scripting.FileSystemObject")
 If (filesys.FileExists(Source)) Then
 filesys.MoveFile Source,Dest
 End If
End Sub
VBEND

let>Source=%Desktop_Dir%\renameMe.txt
let>Dest=%Desktop_Dir%\renameMe2.txt


VBRun>MoveFile,%Source%,%Dest%

MoveFile is used to also rename a file. So just change the Source and Dest in the Let> statements.

Place the script at the top of your macro. That's VBStart to VBEnd. Then insert the two lets and the vbrun
where you want to call the rename script.

Hope this helps,
PepsiHog
MS v14 Windows 10

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2018) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Fri Jul 05, 2019 11:48 am

Thank you!

CGooley
Newbie
Posts: 17
Joined: Tue Jun 25, 2019 6:13 pm

Re: Rename File Trouble

Post by CGooley » Fri Jul 05, 2019 5:10 pm

Hi JRL,

I think I have to go this route, as even the VB script encounters a renaming issue, due to the way OCR is capturing.

In the validation script you provided, Is there some reason why my message output would be vSTrN/Code? I couldn't find any errors.

Let me know what you think? Thanks again for your help.
JRL wrote:
Wed Jul 03, 2019 9:46 pm
Here is a sample of one way to filter out unwanted characters. This example removes tab and Carriage Return Line Feed from the string.

Code: Select all

//Sample string with most typeable special characters
Let>vStr=~` !1@2+#3$4%crlf%5^6&7*8(9)0_aBc_Fg-+={[}]|\:;"'<,>.?/

//Splits string into components
RegEx>.,vStr,0,var,var_count,0

Let>vStrN=
Let>cc=0
Repeat>cc
  Add>cc,1
  Let>value=var_%cc%
  
  //Special allowance for double quote
  If>value="
    Goto>AddAnyway
  EndIf
  
  //Special removal for CR and LF
  If>{(%value%=%cr%)or(%value%=%lf%)}
    Goto>Remove
  EndIf
  
  //Convert character to its ASCII Number
  VBEval>ascW("%value%"),vAsc
  
  //The filter.  Keep Char if in range
  If>{(%vAsc%>31)and(%vAsc%<127)}
  
  Label>AddAnyway
    Let>vStrN=%vStrN%%value%
  EndIf
  Label>Remove
Until>cc=var_count

Let>msg_width=500
MdL>vStrN/code]
[/quote]

User avatar
JRL
Automation Wizard
Posts: 3262
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Rename File Trouble

Post by JRL » Fri Jul 05, 2019 7:59 pm

Sorry. I fixed the original posted code.
The left bracket for the closing "code" html got deleted.

The code I posted also partially uses VBScript to convert each character in the string to its corresponding ASCII decimal value. The character """ (double quote) does not pass well to VBScript without being escaped. Rather than doing that I simply skipped the VBEval step.

Post Reply