Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Move Files from one Sharepoint Folder to another

I have a Sharepoint Folder ExampleFiles

and within this folder I have a Archive Folder

In the ExampleFiles folder there can be 1 or Many files

I simply want to move all the files in ExampleFiles into Archive

Ive tried adding a Get files (Properties only) and then using this on a Move files step which is contained in an apply to each container but I Just cant get it to work. 

Can anyone help me on this? Im sure it shouldnt be too complex to move the files

Community Support
Community Support

Hi @debbieedwards,


I have made a test on my side to create the sharepoint folder as below:


Please refer to screenshot below to create the flow:


The expression in the Condition as below:

@and(contains(items('Apply_to_each')?['{Identifier}'], 'ExampleFiles'),not(contains(items('Apply_to_each')?['{Identifier}'], 'Archive')),contains(items('Apply_to_each')?['{Identifier}'], '.'))


The flow would run successfully as below:



Best regards,




Oh wow, Thank you I will get going with this and let you know how I get on Smiley Very Happy



Unfortunately this hasnt worked for me.


I cant save and I get the error


The template validation failed: 'The inputs of template action 'Condition' at line '1 and column '4469' is invalid. Action 'Apply_to_each' must be a parent 'foreach' scope of action 'Condition' to be referenced by 'repeatItems' or 'items' functions.'.


I do have more stuff at the beginning of the flow, like when Files are created in the Sharepoint folder, Copy them to a blob but this all works fine.


Its the condition it doesnt seem to like but I copied as is and I also have an Archive folder in my main folder. Im really stumped with this one. 

I may have made a mistake with my initial ask


I have a Sharepoint Folder Called ExampleFiles

Under this another folder called TypeA

Then in here I have Archive

And the files sit in TypeA

So there is a middle Sharepoint folder. Could this be what is causing the issue?

Hi @debbieedwards,


Please check your flow and make sure your create the flow as me,

The expression in the Condition as below:

@and(contains(items('Apply_to_each')?['{Identifier}'], 'TypeA'),not(contains(items('Apply_to_each')?['{Identifier}'], 'Archive')),contains(items('Apply_to_each')?['{Identifier}'], '.'))


Best regards,


Still getting The template validation failed: 'The inputs of template action 'Condition' at line '1 and column '4469' is invalid. Action 'Apply_to_each' must be a parent 'foreach' scope of action 'Condition' to be referenced by 'repeatItems' or 'items' functions.'. with all the steps above in place. Ive checked a few times. 


I understand its saying that the condition is invalid but I dont know what column 4469 means


Im thining maybe Im doing it wrong. 

I add the apply to each 

Then New Step - Apply to Each and add thy dynamic value from the above Get Files (Properties only)

Within there, add condition. Go into advanced mode and add the code you provided.

Within this New Step Move FIles. Files to move, bring across the identifier.... 


Does this seem correct?

Ok, I think I found the problem I was having. I was using a flow that triggered based on the sharepoint trigger


"When a file is created in a folder"


Which was picking up the newly created files but because I was trying to clean up some shared blobstorage within my flow I was getting problems when multiple new files were added to the location. The flow would run multiple times for each file in parallel and would then hit problems as blob storage list results would go stale when one instance of the flow did its cleanup (removing blobs), invalidating the list blobs results in the other instances.


I've created a new flow now that can run on a recurrence schedule so that I can be sure there's only a single flow running at any time.


This flow can now do the get files (properties only) move task we've been talking about at the end and seems to be working a little better. I've gotten my condition to work that's similar to the one you helped me with above, I needed to fixup the syntax for Apply to each as it was the 2nd apply to each in my flow so required _2 adding to it like this




I was wondering whether there was any good documentation that describes the language of these commands we can use in the advanced syntax? I've tried searching for it but haven't been able to find anything yet. Even the basics to explain the way that you are able to use ? [ ] to look into columns of data would be useful as I'm just working off examples at the moment with no nice reference to read to come up with my own advanced syntax in the future.


The condition now seems to work and correctly performs work only on the files that I want it to do the work on, leaving the existing archive files alone.


I'm getting the file contents of each file and creating a blob for each one of them and then trying to do the sharepoint move file action to move the processed file into the archive. This is where I'm hitting a problem, my flow just runs endlessly being stuck on the first file that I'm trying to move. Everything is setup correctly in the same way as your move task is setup.


Actually debugging it I can see that the first file IS actually moved into the Archive folder, its just the action and therefore the containing apply to each loop just sits there forever until I cancel my flow, leaving any other files it was due to process unprocessed until the trigger runs next time.

If I remove the move file action and leave just the create blob step then the flow finishes within 20 seconds successfully having created the blobs for each file.


I've yet to try just moving the file without creating the blob as its quite clumsy to add and remove actions and I know I definitely need the blob creation step amongst other actions. Is there a way that I can easily copy an action so that I can paste it back into place without having to rebuild it from scratch?


So frustratingly I think my flow is correct, it even seems to work. Just the flow itself hangs running indefinitely with no logging as the current step is still in progress so I can't even debug what's going wrong. The file in question is moved, yet the flow doesn't continue on. Is this possibly a bug with Microsoft flow itself?


I even took a look at the settings for the move file and wondered if anything there could be possibly set to help.. turning off Asynchronous Pattern, or perhaps even setting a timeout for it. I tried using "P20S" hoping that would be a 20 second timeout, however that wasn't a valid syntax. I also presume that if the timeout is exceeded the action and flow would fail rather than continue on? Surely configuring these options beyond the defaults shouldn't be required for a simple move action in a simple apply to each loop?


Thanks again for your time, I feel like I'm so close but I'm truly stuck how to debug this any further as Flow has stopped telling me anything helpful about what is wrong.


Helpful resources

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

Top Solution Authors
Users online (28,686)