web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to avoid deal with...
Power Automate
Answered

How to avoid deal with unwanted attachment? By TWO-IF condition?

(0) ShareShare
ReportReport
Posted on by 50

Hi community

 

If anyone knows how to do it would you please help?

I am currently using PAD free version.

The problem is that the Retrieve email messages from Outlook retrieves unwanted images from signatures.

I am trying to delete them after they are being retrieved into the RetrievedEmails list.

Here is my flow:

キャプチャ.PNG

What I am trying to do is if the file contains "image" and is jpg or png file, then I want to remove them.

Otherwise I would like to change the file's name.

It is not working properly. Is it becasue the way I use if and else if is wrong?

 

 

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    It's because when you use contains, the second operand must all be contained by the first operand for the condition to return true. Your extension will never contain both png and jpg, as it will only contain one of these.

     

    Instead, try using this as the first operand:

    %attachment.Extension = 'jpg' OR attachment.Extension = 'png'%

    And then use Equals as the operator and %True% as the second operand.

     

    This will check for both options separately and will return true if either one of them is the case.

    -------------------------------------------------------------------------

    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

     

  • yiyi Profile Picture
    50 on at

    Hi Agnius

     

    Thank you for your quick reply.

    I changed my flow as what you have wrote above, but the files are not being deleted.

    One of the attachments named image001.png was still renamed. 

    Do you think it is because it needs a little bit time cusion between if clause and rename?

     

    I think I figured it out by putting an else inside if.

     

    IF StartsWith(attachment.name, $'''image''', True) THEN
    ELSE IF (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN
    File.Delete Files: attachment
    ELSE
    File.RenameFiles.RenameAddText Files: attachment TextToAdd: $'''att_%ReceivingDateTime%_%NewAttachmentName%_''' TextPosition: File.AddTextPosition.BeforeName IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles

     

    Thank you again for your help! Very appreciated!

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    This is because you have an IF statement that checks the file name, but does not delete it when true. ELSE IF is only evaluated when the first IF is false. So, your IF is making your flow skip deleting files that have file names starting with "image".

     

    Either remove the original IF altogether and simply use the extensions, or add a Delete file(s) action under the IF statement, too.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • yiyi Profile Picture
    50 on at

    @Agnius 

    Sorry I do have another question.

    Using IF and ELSE IF is an OR relationship.

    What if what I wanted is IF and IF, an AND relationship?

    The file starts with image and is a jpg or an png.

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    If you wanted to do an AND relationship, you would need to do a nested IF - put another IF inside an existing IF. This way, the nested IF will only be checked when the parent IF is true.

     

    Or, you can use operators, similarly like what I showed you in the ELSE IF. You can use the following for a single IF that covers both conditions:

    IF StartsWith(attachment.name, $'''image''', True) AND (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • yiyi Profile Picture
    50 on at

    @Agnius 

    Thank you for your reply. 

    It is interesting that I tried your method and somehow the RPA is still renaming the image files.

    But if I wrote the script this way, it works. I don't understand why but it works.

    IF StartsWith(attachment.name, $'''image''', True) THEN
    ELSE IF (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN
    File.Delete Files: attachment
    ELSE
    File.RenameFiles.RenameAddText Files: attachment TextToAdd: $'''att_%ReceivingDateTime%_%NewAttachmentName%_''' TextPosition: File.AddTextPosition.BeforeName IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    I guess you have some images that do not start with the word "image", which would not be covered by my condition above. This one would cover that, too:

    IF StartsWith(attachment.name, $'''image''', True) OR (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN

    No idea why yours work. It technically shouldn't delete any attachments that have a name that starts with "image". So, I guess, it might work if they're named something else.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

  • yiyi Profile Picture
    50 on at

    @Agnius 

    This is what I have tried and here are its results.

    The file is truly named "image001.png"

     

    ○ the ones that works

     

     

     

     

    IF StartsWith(attachment.name, $'''image''', True) OR (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN
    IF StartsWith(attachment.name, $'''image''', True) THEN
    ELSE IF (attachment.Extension = 'jpg' OR attachment.Extension = 'png') = True THEN

     

     

     

     

    ✖ the ones that do not work

     

     

    IF (StartsWith(attachment.name, $'''image''', True) AND (attachment.Extension = 'jpg' OR attachment.Extension = 'png')) = True THEN

     

     

    IF StartsWith(attachment.name, $'''image''', True) = True THEN
    IF (attachment.Extension = 'png') = True THEN

     

     

     

     

  • yiyi Profile Picture
    50 on at

    Problems seem to be solved by adding '.' in front of each extension.

  • yiyi Profile Picture
    50 on at

    @Agnius 

    Do you mind looking at this code for me?

    IF (StartsWith(attachment.name, $'''image''', True) OR StartsWith(attachment.name, $'''outlook''', True) OR StartsWith(attachment.name, $'''grafika''', True) OR StartsWith(attachment.name, $'''~''', True) AND (attachment.Extension = '.jpg' OR attachment.Extension = '.png' OR attachment.Extension = '.gif')) = True THEN

    Somehow the conditions on "starting with 'grafika'" and "starting with '~'" do not seem to respond.

    And also could you please teach me some other simpler ways to do it?

    Many thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 414

#2
11manish Profile Picture

11manish 331 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard