Torein Posted October 28, 2010 Share Posted October 28, 2010 (edited) I'm trying to remove the end of a variable (in this case a filename) so that it doesn't have "_Page_1" or "_Page_01" or "_Page_001" depending on what the filename is. I feel like I'm missing something on the syntax of the if statements. I've been searching the forums and website for about an hour now trying to figure this part of the script out. Anyone have any ideas? I feel like there should be a less complicated way to do this process. To remove specific strings from a variable. Local $hClipboard ;Defining variable to use for document window name Local $hFilename ; Defining variable to use for the filename $hClipboard = ClipGet() ; Defining variable as document filename If StringInStr($hClipboard, "_Page_01") <> 0 Then $hFilename = StringTrimRight($hClipboard, 8) ; Defining variable as document filename minus the _Page_01 ElseIf StringInStr($hClipboard, "_Page_001") <> 0 Then $hFilename = StringTrimRight($hClipboard, 9) ; Defining variable as document filename minus the _Page_001 Else $hFilename = StringTrimRight($hClipboard, 7) ; Defining variable as document filename minus the _Page_1 EndIf Thank you! Edited October 28, 2010 by Torein Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 28, 2010 Share Posted October 28, 2010 (edited) Replace it all with one line, like: If StringRegExp($sClipboard, ".+_Page_\d+\Z", 0) Then (Not tested) See help file. Edit: That does detection, you would see StringRegExpReplace() to get of stuff at the end. Edited October 28, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Torein Posted October 29, 2010 Author Share Posted October 29, 2010 Replace it all with one line, like: If StringRegExp($sClipboard, ".+_Page_\d+\Z", 0) Then (Not tested) See help file. Edit: That does detection, you would see StringRegExpReplace() to get of stuff at the end. Thank you for your reply! I was looking at the StringRegExpReplace() but couldn't figure out how to make it work. This is what I have right now. The first few functions are to get the filename copied out of the window. Local $sClipboard ;Defining variable to use for document window name Local $sFilename ; Defining variable to use for the filename MouseClick("left", 1374, 713, 1, 10) ; Selects first document in Bottom right window Sleep( 1000 ) ; Wait 1 Seconds MouseClick("left", 1374, 713, 1, 10) ; Clicks again to start renaming process Sleep( 1500 ) ; Wait 1.5 Seconds Send("^c") ;Copy the name of the first document $sClipboard = ClipGet() ; Defining variable as document filename $sFilename = StringRegExpReplace($sClipboard, "+_Page_\d+\Z", "", 0) ClipPut($sFilename) ; Set the new document name to the clipboard Right now it's not even copying to the clipboard. Thanks in advance! Link to comment Share on other sites More sharing options...
enaiman Posted October 29, 2010 Share Posted October 29, 2010 Better use a MsgBox or a ConsoleWrite to display the clipboard content, just before using StringRegExpReplace. If nothing is in clipboard, you will get nothing back SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Torein Posted October 29, 2010 Author Share Posted October 29, 2010 Better use a MsgBox or a ConsoleWrite to display the clipboard content, just before using StringRegExpReplace. If nothing is in clipboard, you will get nothing back Local $sClipboard ;Defining variable to use for document window name Local $sFilename ; Defining variable to use for the filename MouseClick("left", 1374, 713, 1, 10) ; Selects first document in Bottom right window Sleep( 1000 ) ; Wait 1 Seconds MouseClick("left", 1374, 713, 1, 10) ; Clicks again to start renaming process Sleep( 1000 ) ; Wait 1 Seconds Send("^c") ;Copy the name of the first document $sClipboard = ClipGet() ; Defining variable as document filename ConsoleWrite($sClipboard) $sFilename = StringRegExpReplace($sClipboard, "+_Page_\d+\Z", "", 0) ClipPut($sFilename) ; Set the new document name to the clipboard ConsoleWrite($sFilename) The $sClipboard is coming up with the filename most of the time. It doesn't always catch it though. But regardless if it catches it the $sFilename has no variable. Maybe the StringRegExpReplace command is replacing everything with the blank? I'm trying to get "Alcon_Infiniti_OZil_and_U_S_Handpiece_211860001_RevL_tr_Page_1" to Alcon_Infiniti_OZil_and_U_S_Handpiece_211860001_RevL_tr". Link to comment Share on other sites More sharing options...
Torein Posted October 29, 2010 Author Share Posted October 29, 2010 Just updating since it won't let me edit my previous post. If anyone has a better way to copy the name of a file at the beginning of a directory than I have set up in my previous post please let me know! This seems to work $sFilename = StringRegExpReplace($sClipboard, "_Page_(\d)(\Z)", "", 0) unless I have a filename like "Alphatec_TAMARACK_Anterior_Thoracolumbar_Plating_System_INS_013_RevB_tr_Page_01" then it doesn't modify it. How can I make the script remove anything at the end of the string that has _Page_1 or _Page_01 or _Page_001? Thanks in advance! Link to comment Share on other sites More sharing options...
Varian Posted October 29, 2010 Share Posted October 29, 2010 Wouldn't this work if the expression always starts with "_Page" and ends with "1"StringRegExpReplace($var, "(?i)_Page_.*1", "") Link to comment Share on other sites More sharing options...
Torein Posted October 29, 2010 Author Share Posted October 29, 2010 Wouldn't this work if the expression always starts with "_Page" and ends with "1"StringRegExpReplace($var, "(?i)_Page_.*1", "") Yeah that looks right. This ended up working for my needs as well $sFilename = StringRegExpReplace($sClipboard, "_Page_(\d+\Z)", "", 0) I'm still having issues copying the first filename in the directory. I'm going to post that in a new topic though. Thanks everyone for the help! Link to comment Share on other sites More sharing options...
Varian Posted October 29, 2010 Share Posted October 29, 2010 In what kind of window is the MouseClick operating? Explorer? Is it a control in a window where you can read the contents? Link to comment Share on other sites More sharing options...
Torein Posted October 31, 2010 Author Share Posted October 31, 2010 In what kind of window is the MouseClick operating? Explorer? Is it a control in a window where you can read the contents? It is an explorer window. Not sure how the controls work. I'll have to read up on that. This is what I ended up doing instead and it works great! Local $sClipboard ; Defining variable to use for document window name Local $sFilename ; Defining variable to use for the filename Local $search $search = FileFindFirstFile("D:\BPP\Working\Tiff\Out\*.tif") ; Initializing FileFind? Not sure why this is necessary but it didn't work otherwise $sClipboard = FileFindNextFile($search) ; Whatever is the first file in the directory gets set to the variable If $sClipboard = "" Then ; Will exit macro if there are no files in the directory Exit Else $sFilename = StringRegExpReplace($sClipboard, "(?i)_Page_.*1.tif", "", 0) ; Remove the _Page_*1.tif from the end of the filename within the variable ClipPut($sFilename) ; Set the new document name to the clipboard I also have this all on a loop that will repeat however many times the user inputs. What's nice is if the user puts in too many times to repeat it the macro will automatically stop itself when it's finished with the files in that directory (I have the macro move the files to another folder during the process.) I'll be adding a sound to the macro and updating another adobe acrobat combine macro later. It's so nice to be able to set the macro up to combine hundreds of documents together Thanks for the help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now