Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Scan an incoming folder, and move files based on filename to folders with same name

Hi everyone,


I'm still very new to Flows, and I'm trying to automate some document filing.


We've got a sharepoint library folder where PDFs get dumped with client names included in the file name.  I'm trying to design a flow that will check that folder say once an hour (or even just once a day), then look in another folder at all the subfolders and find a folder that contains a name that's on the filename of the PDF.


It definitely won't be able to find a match on every one, which is ok, but even if it can file 75% of the documents there it will help.


So the PDF name is something like 2019_April_AS_CLIENTNAME  and then the folder contains a whole ton of folders that are the client name.  And we want it to file the document something like CLIENTNAME FOLDER/DOCS/2019 or similar...


It's based on financial year, so we can't just the year necessarily at the beginning of the file name.  But I can tailor that if I can get the scanning and recognising working first...

Memorable Member
Memorable Member

Hello @Charlesk have you already build something?


I do not have same case running but I beleive that we can achieve it as I am also using listing all items in document library and looking for folder names.


Solution Sage
Solution Sage

Hi @Charlesk ,

It seems you want to move the PDF file to the corresponding folder.

I have made a test on my side, please take a try with the following workaround:

In my SharePoint, there are two libraries, lib1 and lib2.

I uploaded the PDF file in lib1, then move the file to the corresponding folder in lib2.

The file in lib1:


The folder in lib2:


Expression in Compose 2: last(split(outputs('Compose'),'_'))




Best Regards,

Community Support Team _ Zhongys

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.


Frequent Visitor

@v-zhos-msft  Hmmm, thanks.  Rather than just copying in a demo sharepoint I want to try to understand it.


Can you please explain how that's working? I don't quite understand the Compose or the Last(split...  etc component.  Do you mind please explaining it in words for me?

Hi @Charlesk ,

As the pic showed, the Compose action is to get the file name(2019_April_AS_CLIENTNAME).

The expression in Compose 2 is to get the CLIENTNAME.

split(outputs('Compose'),'_') will return an array ['2019','April','AS','CLIENTNAME']

Last() will return the last element of the array.

For more information about the function, please take a reference below:

Best Regards,

Community Support Team _ Zhongys

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-zhos-msft 


Do you think a "contain" function would be able to match say the first 5 characters of CLIENTNAME on the file to the first 5 characters of the folder name to find a match?


IE we don't need an exact match, but the first 5 characters only?


The issue is that the file name is often CLIENTNAME, but the folder name is CLIENT NAME.  It's too hard to rename all the client folders to remove spaces etc...

Not applicable



I copied your flow but it does not work for me. 

The expression result is always false and it always gives me this error. 

"ActionFailed. An action failed. No dependent actions succeeded."


Any help? 





Helpful resources



Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

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

Users online (1,560)