Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

Move file to a folder in the SP library , in a folder where filename and folder name are the same?

(0) ShareShare
ReportReport
Posted on by 60

Hello,
I have a folder "inbox" in a SP document library. Every day there will appear some files in that folder eg.
Filename AAA1
Filename BBB2
Filename CCC3

Somewhere within that SP document library there are also folders called AAA1 and BBB2 and CCC3.
Now I want to build a flow in PowerAutomate where it automatically moves that file AAA1 from the inbox in
folder AAA1 .... but that AAA1 folder can be somewhere in the SP library. PowerAutom. should dynamically
search oder filter for that folder, so that it finds the correct folder and moves the file there.

How could that be done? Thanks in advance


  • mjp1973 Profile Picture
    60 on at
    Re: Move file to a folder in the SP library , in a folder where filename and folder name are the same?

    Hi, the flow you described works also with multiple files without Apply to each but I am still testing.

    I still have one problem because the files that arrive look like this eg. BT-17901_LCCX185.pdf but it should only look for folder names/subfolders like BT-17901 up to the _ underline sign otherwise it would not find a match.
    Where and how could I place there any expression only to take the text up to the underline and find a matching subfolder to move to  

    mjp1973_2-1679952386274.png

     

    mjp1973_1-1679952378828.png

     

  • mjp1973 Profile Picture
    60 on at
    Re: Move file to a folder in the SP library , in a folder where filename and folder name are the same?

    Hi,

    The real life flow should be....like that.... not sure if your nice described previous flow can do that. By the way, thanks for your time with all your screenshots. 

    Path:  Documents > Appmanagement and Service > German Service > Inbox

    That is where the files arrive at the beginning, all of them in the Inbox folder

    --------------------------------------------------------------------


    Here some of the paths where the files should automatically get moved to using Move files... some examples... the important part is always the folder name at the end eg. BA-2030 because when a file like BA-2030.pdf or doc arrives in the inbox it should automatically get moved to that folder BA-2300 .... and so on, or if the file name contains in the beginning BA-2030 or so.


    Documents > Appmanagement and Service > German Service > Places > Middle > Main street > BA-2300


    or could also be ....


    Documents > Appmanagement and Service > German Service > Places > Noth > Little street > BA-7500


    or could also be any similar....


    Documents > Appmanagement and Service > German Service > Places > South > Citizen street > BA-17200

  • mjp1973 Profile Picture
    60 on at
    Re: Move file to a folder in the SP library , in a folder where filename and folder name are the same?

    Thanks a lot, yes that is what I was looking. Sorry for my late reply, i was sick for some days.

  • Verified answer
    grantjenkins Profile Picture
    11,059 Super User 2025 Season 1 on at
    Re: Move file to a folder in the SP library , in a folder where filename and folder name are the same?

    Hopefully this is what you're looking for.

     

    For this example, I have the following Library and folders.

    grantjenkins_0-1677992487189.png

     

    grantjenkins_1-1677992511799.png

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_2-1677992568025.png

     

    When a file is created it triggered when a new file is created in the Inbox folder.

    grantjenkins_3-1677992608863.png

     

    Get files retrieves folders where the name is equal to the name of the file just created.

     

    //FSObjType eq 1 means only return folders (not files)
    
    //FileLeafRef refers to the Name of the folder
    
    FSObjType eq 1 and FileLeafRef eq '@{triggerOutputs()?['body/{Name}']}'

     

    grantjenkins_4-1677992716014.png

     

    Condition checks to see if one item (folder) was returned from Get files. If true, we go into the Yes branch. The expression used in the condition is:

     

    length(outputs('Get_files_(properties_only)')?['body/value'])

     

    grantjenkins_6-1677993061524.png

     

    Move file uses the Identifier from When a file is created. And uses the following expression to get the Full Path of the folder. You can choose what you want to do if a file with the same name already exists within the folder.

     

    first(outputs('Get_files_(properties_only)')?['body/value'])?['{FullPath}']

     

    grantjenkins_5-1677992882525.png

     

    If no folders were found, or if it found more than one folder with that name, it would go into the No branch where you could possibly send an email to yourself/others letting you know the file that was uploaded hasn't been moved.


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • mjp1973 Profile Picture
    60 on at
    Re: Move file to a folder in the SP library , in a folder where filename and folder name are the same?

    It is actually about.... a file eg. "16.docx" gets saved in a inbox folder of the sharepoint library. Now PowerAutomate should dynamically search for a folder called "16"  within that sharepoint library .....and move the file "16.docx" automatically to this folder "16" .... using Move file.  

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