Rename File Trouble
Moderators: JRL, Dorian (MJT support)
Rename File Trouble
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
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
Re: Rename File Trouble
I think it may have something to do with a dollar sign in amount?
Re: Rename File Trouble
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.
Re: Rename File Trouble
Any ideas? GetTextInRect>left,top,right,bottom,result_variable does not work, and i'm using adobe.
Re: Rename File Trouble
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
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
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) 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!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) 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!
Re: Rename File Trouble
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.
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.
Re: Rename File Trouble
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.
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
Re: Rename File Trouble
@CGooley,
Happy Scripting!
VB Script to rename a file.
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
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%
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
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) 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!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) 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!
Re: Rename File Trouble
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.
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 pmHere 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]
Re: Rename File Trouble
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.
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.