cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
igonzalez1
Frequent Visitor

Get most recent file in a onedrive for business folder

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.

5 REPLIES 5
v-duann-msft
Community Support
Community Support

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

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.

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

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
Community Support
Community Support

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

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (90,046)