Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
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,548 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
    698 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,549 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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

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

Leaderboard > Power Automate - Using Flows

#1
stampcoin Profile Picture

stampcoin 30

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 30 Super User 2025 Season 1

#3
RP-25090907-0 Profile Picture

RP-25090907-0 23

Overall leaderboard

Featured topics

Restore a deleted flow
Loading started