cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
benny_blanco
Helper I
Helper I

Get substring from file name and move to matching SharePoint Online folder

Hi,

I'm having difficulties trying to achieve the following scenario using Power Automate - I have a document library holding many folders. Each folder is named after an individual employee and her/his ID number, for instance John Doe, 1111111, the ID will always come after a comma, or some other separator. There is another document library, to which files for these employees will be uploaded. The file names will contain the name and the ID of the employee. Now what I'm trying to achieve and create an automation for is, to get the ID number out of the name of the file as it'll always be unique, out of the whole string, then look for the folder in the first document library holding all user folders containing this substring and based on that, to move it to that folder that matches the ID substring. Any help/ideas will be very much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @benny_blanco,

 

Yes, after you get the ID, please refer to the following steps:

Annotation 2020-05-08 172205.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
v-litu-msft
Community Support
Community Support

Hi @benny_blanco,

 

You could use the split() function to convert the file name into an array, for example:

split('John Doe, 1111111',',')

The result will be:

[

"John Doe"

"1111111"

]

Then you could use last() function to get the "1111111", for example:

last(split('John Doe, 1111111',','))

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for the formula! Replaced the name and ID part with the dynamic value of the actual document name and it is separating and returning everything after the separator. Any ideas on how to make it look for the one folder that contains the same ID information and to move it there automatically?

Hi @benny_blanco,

 

Yes, after you get the ID, please refer to the following steps:

Annotation 2020-05-08 172205.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thank you for that! Let me test and will let you know.

 

Cheers!

Hi @v-litu-msft ,

 

Thank you, it worked! 

 

Something else I want to ask though about the formula you provided - it gets everything after the separator, but gets the file extension as well (.pdf, .docx). How can I make it work without getting that part, the file extension?

Hi @benny_blanco,

 

Use the split() function again, separate by ".", for example:

first(split('1111.excel','.'))

It will return: 1111

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-litu-msft  - Can I ask you for some help again as I can't figure it out. It turns out the actual string looks like this -

 

JonasSmith-Joe-1234567-CLMPDVVD-TB.pdf

 

and I need to extract only the ID part, only the digits you see and then look for that ID in the folders, if they contain it. How can I extract the ID alone first, then the name at the beginning alone again? Thank you for the support!  

Hi @benny_blanco,

 

Use the split() function could do it:

split function could separate a string by a substring, convert it into an array, then index could extract member of the array:

split(outputs('Compose'),'-')[2]

Annotation 2020-06-05 153814.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you as usual! Will try it and let you know.

@v-litu-msft -Thank you, works perfect and depending on the digit inside of the brackets, I can manipulate what to return, after which - sign.

benny_blanco
Helper I
Helper I

@v-litu-msft  - Hi, hope you are doing well? If I could ask you again for an advice and possible resolution to my task. You helped me a lot so far, but now I'm struggling for days to achieve the following - Once a file is created in a SharePoint folder, for the demo purposes let's name it Library1, I need to extract the file's ID from the name string of the file, which will be something like this - JohnDoe-JD-012345-DF-CONF.docx, so I need just the 0123456 part. Then I need to find the folder within that main folder Library one that contains that ID, something like folder JohnDoe_0123456 and place that file there. That you helped me with and I think is working fine now. The new part is, if the ID of the document is not included in any folder (that means that there's no such user in the folder), the folder to be created in the main Library1 and the file placed inside. Also each of these user folders within the main Library1 folder will have to subfolders inside called "Confidential" and "General". So what I have to also achieve is not only to place the document to its corresponding folder that contains its ID, but if the document also contains CONF in its name, to place it inside the Confidential folder, if not, in the General? Have been trying for days with no result whatsoever. Any help would be very much appreciated, thank you in advance!

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

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,591)