cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Flow to Count files in a Sharepoint Folder

Hello, 

 

We have a task that requires a staff member to process files in a group of sharepoint folders, and once completed, move the file into a "Done" folder. 

I want to create a flow that runs daily via the Recurrence Trigger, does a count of all the files within the root folder, and adds that to a variable to be emailed.  

Any advice/ideas on the best way to go about doing this?

1 ACCEPTED SOLUTION

Accepted Solutions

Sorry I should've read your message better. You need to use Get Files Action instead.  That one lets you get documents from a library.  

 

The formula would be slightly different.  Need to change it to the name of the Get Files action

 

"@length(body('GetFiles')?['value'])"

View solution in original post

17 REPLIES 17
aprildunnam
Power Participant
Power Participant

You can use the Get Items Action and point that to your SharePoint Library.  Then add a Compose action and use this formula to get the number of items:

 

"@length(body('Get_items')?['value'])"

 

Anonymous
Not applicable

@aprildunnam Thanks for the reply, i'll have a go at using the formula and let you know how i go. Appriciate the help. 

Anonymous
Not applicable

@aprildunnam Tried the Get Items function, but this seems to only pull from a sharepoint list, but i want to count the files in a folder. 

 

Capture.PNG

Sorry I should've read your message better. You need to use Get Files Action instead.  That one lets you get documents from a library.  

 

The formula would be slightly different.  Need to change it to the name of the Get Files action

 

"@length(body('GetFiles')?['value'])"
Anonymous
Not applicable

Is this the Compose step your describing? If so this is the error im getting

 

Capture.PNGCapture2.PNG

Yes that's it. The issue is the text where is says "Get Files" in the parenthesis needs to match the name of your action above.  So if you click the "..." in your Get Files action and rename it to "GetFiles", just like that, all one word then the compose action will work

Anonymous
Not applicable

Awesome, that did the trick, thanks for the quick replies 🙂 

Can you provided a little more inforamtion about the Get File Action. Under Sharepoint I see no option for Get Files alone. There is Get File Properties, and Get Files (Properties Only). 

Anonymous
Not applicable

@scoombs i used Get Files (properties only) for sharepoint.

Im also trying to get a file count on a folder within Sharepoint. I've setup a recurrence schedule to send out email every hour. This folder is under another folder. The address appears http://mysharepointsite. sharepoint.com/site/IT and a directory under IT.  

SharepointFolderTocount.png

 

Within the Disaster Recovery folder there are five files I would like to count. When I run my flow 

 

FileCount.png

 

I get an email with the Output values of 100. 

 

 

 

Anonymous
Not applicable

Yes mine also caps at 100 - ive yet to find a solution to this, for me, i just put a condition in saying if its over 100 to send a slightly different notification. Which meets my purpose. 

The problem is the Sharepoint folder I'm trying to target only contains 5 files.  The email I receive reports the count (Output from the Compose Step) = 100. 

 

Compose-Output.png

Anonymous
Not applicable

Might be bests to create a new topic, someone probally has a solution to that, may even have something to do with the file types? Mine are all PDF's . 

 

Counts are accurate for me under 100, but when our runs have more than 100, it does cap at 100. 

Anonymous
Not applicable

Hi,

 

I tried to replicate the same steps where i'm trying to fetch the total count within site assets library. Flow runs but when checking the count displayed by Microsoft flow it is not tallying with the count being displayed in sharepoint (Navigating to Gear icon --> Site contents--> Site Assets (Count).

 

Please advise.

 

Regards,

Kushal Bhowmick

Hi April,

 I've just come across this and unfortunately the expression is reporting as invalid. Even if I just type it manually - I'm guessing its been updated or something since this? I've looked at other articles and they pretty much still have this expression as the solution - so I'm kinda stuck. Can you help?

Thanks,

Jason.

Luber
Frequent Visitor

As I'm  finding often on this forum, the UI or syntax has changed since the solution was posted, so it no longer works.

The SharePoint Get files (properties only) now has 4 lines, and and neither "body" nor "value" returns a list (even though both say they're a list - although you can see "value" has the list icon, and "body' has the ABC icon).

Screenshot - 1_5_2021 , 1_53_17 PM.png

This fails for me with either Compose formula

length(outputs('Get_files_in_New_Assets')?['body'])
 
InvalidTemplate. Unable to process template language expressions in action 'Compose_No_Files_in_New_Assets' inputs at line '1' and column '64012': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#length for usage details.'.
 
or
length(outputs('Get_files_in_New_Assets')?['value'])
 
InvalidTemplate. Unable to process template language expressions in action 'Compose_No_Files_in_New_Assets' inputs at line '1' and column '64012': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#length for usage details.'.

Screenshot - 1_5_2021 , 1_19_25 PM.png



Hi @Luber 

 

I had tested from my side and found that to resolve the error, all you have to do is just add an Initialize variable action to convert the output into the array. 

This is because we understand that the length(...) formula in the expression editor is only able to count the output/data which is array or string only. 

 

Hope this helps ~Get files settingGet files settingChoose the right dynamic valueChoose the right dynamic value

 

Add initialize variableAdd initialize variable

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (1,903)