Sign in to follow this  
Followers 0
Torein

If Statements and Conditional Operators

10 posts in this topic

#1 ·  Posted (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 by Torein

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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".

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Wouldn't this work if the expression always starts with "_Page" and ends with "1"

StringRegExpReplace($var, "(?i)_Page_.*1", "")

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

In what kind of window is the MouseClick operating? Explorer? Is it a control in a window where you can read the contents?

Share this post


Link to post
Share on other sites

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 :graduated:

Thanks for the help!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0