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 define the olde...
Power Automate
Answered

How to define the oldest file in a sharepoint folder

(0) ShareShare
ReportReport
Posted on by 22

So I have a flow that automatically downloads a file from an email into folder "Newest". What I want is that if the count of files in the folder exceeds 10 files the oldest file is then moved to the "Archived".

 

I have up to the count bit working with the condition. What I am having trouble with is getting the oldest files name to then use in the move file action. I know this is probably easy but I am relatively new to flow and it is driving me mad!

 

 

image.png

Categories:
  • Verified answer
    efialttes Profile Picture
    14,756 on at

    Hi!

    My suggestion is to play with 'Order By' input in 'Get files (properties only)' , try to tipe the following

     

     

     

    Created asc

     

     

     

     So it should order the results taking into account 'Created' field (date time file was uploaded) in ascending order

     

    If so, you can identify the oldest one by using first() based expression

     

     

    first(body('Get_files_(properties_only)')?['value'])

     

     

     

    You can identify its File identifier by means of the following expression

     

     

    first(body('Get_files_(properties_only)')?['value'])?['{Identifier}']

     

     

    THen use the Identifier  to delete the file

    Flow_DeleteOldestFile.png

    Please be extremely careful when testing 'Delete files' service logic. Use a test Library with test Files first

    Hope this helps

  • Ali_Cabral Profile Picture
    22 on at

    I may have gone a long way about it but by using this I did get there. i had to find the end points of the string and then used the substring to get the variable name. If you don't mind could you help with one more thing. How would I loop it back to the condition so that it would keep going until there are ten files?

  • efialttes Profile Picture
    14,756 on at

    Hi!

    So, the issue you described in your first post is now solved, right?

     

    If so, my humble suggestion:

    1.-Mark this topic as "Solved" by clicking "Accept as a solution". This way other community members facing this same problem in the future have the chance to find a solution faster. Please note you can even select several replies as as 'Solution', even from different community members!

    Flow_AcceptSolution.png

    2.- Open a new thread for your next question, following the policy: 'One Question, one post'. MAny SuperUsers pay more attention to unanswered topics, and this one already have too many. Let's hope somebody else can point us to the right direction

     

    Thanks for making this community great!

  • Ali_Cabral Profile Picture
    22 on at

    Gracias Korosensei.

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
11manish Profile Picture

11manish 292 Super User 2026 Season 2

#2
Henil Profile Picture

Henil 128

#3
anirudhev Profile Picture

anirudhev 124

Last 30 days Overall leaderboard