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 / When a new file is cre...
Power Automate
Answered

When a new file is created, automatically delete a file

(0) ShareShare
ReportReport
Posted on by 75
Hi everyone - 
I am building a flow that will automatically upload an attachment to a Teams folder based upon the parameters that I define.  The attachment will always be from the same sender, it will always be sent on a Tuesday, and it will always have the file name beginning with Offer Data Report (no HR) for Recruiting YYYY-MM-DD-HH-mm.xlsx.  The date at the end of the file name reflects the Tuesday on which the report was automatically created.  I have figured out how to automatically get the email attachment into the Teams folder using the flow below:
The second part is what I am having trouble with...when a new file is created in the Teams folder, I want the file from the previous Tuesday to be deleted (my goal is to only have the most updated version of the report in the Teams folder at any given time).  I thought that using a Get files (properties only) action and a Delete files action would be the best way to go.  This is how far I've gotten with that: 
Does anyone have suggestions on the expression I would put in the Filter Query to only pull the files that were created prior to the date of the most recent file upload?  Again, this will always be on a Tuesday and the file name will always contain Offer Data Report (no HR) for Recruiting.  
 
Thank you!
Categories:
I have the same question (0)
  • Suggested answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at

    Hi,

    Use the Get files (properties only) action with the OrderBy property to sort files by the Created date in descending order. This will allow you to pull the most recent file first. Set the Top Count to 1 (to only retrieve the most recent file).

    To only pull files matching the naming pattern. Use:
    startswith(Name, 'Offer Data Report (no HR) for Recruiting')
  • JD-03091828-0 Profile Picture
    75 on at
    @SudeepGhatakNZ - thank you - this is helpful!  I think that the startsWith function is wanting a string for the column name.  What would I need to do to convert the column name into a string?  And, would I put this statement into Filter Query or into Limit Columns by View?  I will need to use this function as the flow is not running due to the number of items in the list view threshold.  Thank you!
  • Verified answer
    SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at
    This is what I meant.
     
  • JD-03091828-0 Profile Picture
    75 on at
    Hello - thank you very much for the clarification.  I took a bit of a different approach as I was having trouble getting the filter query to work and added a List Folder and Condition step: 
     
    If both conditions are met, nothing will happen.  If conditions are not met, the file will be deleted.
     
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 86 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 55

#3
Ellis Karim Profile Picture

Ellis Karim 53 Super User 2026 Season 1

Last 30 days Overall leaderboard