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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get most recent file i...
Power Automate
Unanswered

Get most recent file in a onedrive for business folder

(0) ShareShare
ReportReport
Posted on by 10

I have a folder in Onedrive for business. This folder contains thousands of files and new files are being added on a regular basis.

I want to get the last modified date of the most recent file using power automate.

 

I tried using "List files from folder" but it will only give me a list of 20 files, sorted by name and not by last modified date.

Categories:
I have the same question (0)
  • v-duann-msft Profile Picture
    on at

    Hi @igonzalez1

     

    Thank you for posting.

     

    According to your description, you would like to check the latest modified file from onedrive. If any misunderstanding. Please kindly let me know.

     

    We can configure as below:

    1.Add a button trigger.

    2.Add OneDrive connector List files in folder.

    3.Initialize variable, set Name as LastM, Type as Array.

    4.Add Apply to each, inside the Apply to each add the action Append to array variable. Set Name as LastM, and set Value with the following code:

    ticks(items('Apply_to_each')?['LastModified'])

    5.Under the Apply to each, add a Compose action with the following code to get the Max value:

    max(variables('LastM'))

    6.Add Apply to each 2, select output Value from the action List files in folder.

    7.Within the Apply to each, add a Condition with the following configuration to get the Max one:

    @equals(ticks(items('Apply_to_each_2')?['LastModified']), outputs('Compose'))

    8.Under if yes branch, add a Compose to return the file name.

     

    Flow overview:

    v-duann-msft_0-1618456636599.png

     

    Flow in detail:

    v-duann-msft_1-1618456636603.png

     

    v-duann-msft_2-1618456636607.png

     

    Once tested, I’m able to get the latest file.

    v-duann-msft_3-1618456636610.png

     

    Hope the content above may help you.

     

    Best regards,

    Anna

  • igonzalez1 Profile Picture
    10 on at

    Thanks for the reply @v-duann-msft 

    I tried that before asking my question. The real problem comes up when the folder contains tens of thousands of files. How can I get the latest last modified date among the tens of thousands of files? As far as I know, List files from folder will only return the alphabetical first 20 elements of the folder. 

     

    Hopefully without having to loop through every single file, wasting precious quota.

  • v-duann-msft Profile Picture
    on at

    Hi @igonzalez1

     

    Thank you for your update.

     

    You are right, the default limitation of ‘List files in folder’ is 20. However, we can enable Pagination settings and increase limit to 100,000 at most.

    v-duann-msft_0-1618474455087.png

     

    v-duann-msft_1-1618474455095.png

     

    I have already tested from my end and I’m able to get more than 20 files in total.

     

    If you need to exceed 100,000 and request larger limit, you can only go to UserVoice to suggest this idea.

    https://powerusers.microsoft.com/t5/Power-Automate-Ideas/idb-p/MPAIdeas

     

    Hope it helps.

     

    Please click Accept as Solution if my post is helpful to you. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

     

    Best regards,

    Anna

  • igonzalez1 Profile Picture
    10 on at

    Hello @v-duann-msft

    Thanks, I already knew about pagination. Please, correct me if I'm wrong, but I believe pagination will increase the number of API calls of the flow and that seems unreasonable for such a simple task like getting the most recent file of a folder.

    Is there any other way to get files from the list of files sorted by last modified date instead of alphabetically? For example, what would one have to do to list the 20 most recent files in a folder? Do I really need to use pagination and loop through every single file?

  • v-duann-msft Profile Picture
    on at

    Hi @igonzalez1

     

    Thank you for your reply.

     

    Yes, you are right. The additional requests from pagination count as action executions as well. But seems there is no any other good idea to return plenty of files within one action.

     

    I recommend you go to UserVoice to post your idea.

    https://powerusers.microsoft.com/t5/Power-Automate-Ideas/idb-p/MPAIdeas

     

    Hope it helps

     

    Best regards,

    Anna

  • Ansari_rpa Profile Picture
    24 on at

    Thanks for the Solution!!

  • JB261 Profile Picture
    on at

    hi @v-duann-msft i used the same solution above but my scenario is I want to display the output in PVA, the flow executes well in power automate but the output in my chatbot is not what I want, what I want to be the output is the name of the folder (latest uploaded). Please see the SS below for more details.

     

    This is what i used in PVA output.

    JB261_0-1678749397476.png


    and this is the result in chatbot.

    JB261_1-1678749438804.png

     

    Thanks, in advance!

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard