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.
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:
5.Under the Apply to each, add a Compose action with the following code to get the Max value:
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:
8.Under if yes branch, add a Compose to return the file name.
Flow in detail:
Once tested, I’m able to get the latest file.
Hope the content above may help you.
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.
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.
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.
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.
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?
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.
Hope it helps
Check out the new Process Advisor community forum board!
Check out new user group experience and if you are a leader please create your group
On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks