Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Copy files and create new folder within Sharepoint using part of filename(multiple filenames to one folder)

(0) ShareShare
ReportReport
Posted on by 4

Hi

I have a Sharepoint folder that is added to regularly with different filenames. I need to copy these files in to new folders within another Sharepoint library based on part of the filename.

 

the files all have a fixed filename format as below:

 

Audit_Jobid_1234_Span_2345

Workpack_JobID_1234_span_2345

Consent__JobID_1234_span_2345

Audit_Jobid_1235_Span_2346

Workpack_JobID_1235_span_2346

Consent__JobID_1235_span_2346

 

And so on,

 

I need to create one new folder for each unique JobID with this  number as the folder name and then copy all files from the source with the matching JobID in to the new folder either whenever a file is added to the Source(which is done automatically) or on a regular occurence(daily?)

 

Is this possible? I've tried all the suggestions on search forums but none quite seem to match the requirements.

 

Thanks

  • v-jefferni Profile Picture
    on at
    Re: Copy files and create new folder within Sharepoint using part of filename(multiple filenames to one folder)

    Hi @Chalky23456 ,

     

    The codes I provided need to be paste in the input area directly rather than in expression input area. If the code is expression, it should be like below:

    triggerOutputs()?['body/{Path}']

    and

    split(triggerOutputs()?['body/{Name}'],'_')[2]

     

    Best regards,

  • Chalky23456 Profile Picture
    4 on at
    Re: Copy files and create new folder within Sharepoint using part of filename(multiple filenames to one folder)

    Thank you for this, however when I try to use the split formula it tells me the expression is invalid? 

     

    Do I need to edit this to suit my files?

  • Verified answer
    v-jefferni Profile Picture
    on at
    Re: Copy files and create new folder within Sharepoint using part of filename(multiple filenames to one folder)

    Hi @Chalky23456 ,

     

    You can create an instant flow where help you make an initial folder structure and copy existing files for the first time. After the preparation is done, disable this instant flow and then create an automated flow that will be triggered by new file adding into the library. 

    vjefferni_2-1700815570575.png

     

    folder path

    @{triggerOutputs()?['body/{Path}']}@{split(triggerOutputs()?['body/{Name}'],'_')[2]}

     

    Best regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1