Skip to main content

Notifications

Community site session details

Community site session details

Session Id : LeT278rhsr+tc5P/ZAm4F6
Power Automate - Using Flows
Suggested answer

Get the latest 5 files inside "List Files in folder" onedrvice action

Like (1) ShareShare
ReportReport
Posted on 23 Jul 2024 13:39:06 by 1,546 Super User 2024 Season 1
I have the following action to "List the Files inside a Folder":-
 
 
 
 
now how i can only get the latest (based on the modified date) 5 files?
 
i used this formula to get the id of the latest file:-
 
last(sort(outputs('List_files_in_folder_2')?['body/value'], 'LastModified'))?['Id']
 
but how i can get the 5 latest files? i can not find a way to do LastN()?
  • Suggested answer
    Sayan Profile Picture
    694 Super User 2025 Season 1 on 24 Jul 2024 at 08:44:56
    Get the latest 5 files inside "List Files in folder" onedrvice action
    Hey,
     
    Solution:
     
    Step 1:
     
    Initialize a variable which is an Array type.
     
    Get the files from the folder
     
    Step 2:
     
    Set a Variable by using the following expression to get the 5 files.
     
    take(reverse(sort(outputs('List_files_in_folder')?['body/value'],'LastModified')),5)
    Workflow:
     
     
    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Thanks,
    Sayan Patra | RPA Developer
     
    If my suggestion helps you, please gives it a Thumbs up and Marks as a Solution. Which motivates to solve more problems.
  • Michael E. Gernaey Profile Picture
    42,027 Super User 2025 Season 1 on 23 Jul 2024 at 18:28:26
    Get the latest 5 files inside "List Files in folder" onedrvice action
    Hi,
     
    So you need to do 3 things
    1) sort them by LastModified
    2) reverse it
    3) use the Take expression to take the first 5 based on step 2
     
    Now you have the last 5
     
    So in my example, I did this
     
    And my Sort/Reverse/Take is here
    take(reverse(sort(outputs('List_files_in_folder')?['body/value'],'LastModified')),5)
     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Using Flows

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 9 Super User 2025 Season 1

#2
rzaneti Profile Picture

rzaneti 7 Super User 2025 Season 1

#3
lbendlin Profile Picture

lbendlin 4 Super User 2025 Season 1

Overall leaderboard

Featured topics

Restore a deleted flow