Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Suggested answer

Simple Move File functionality Not That Simple

(2) ShareShare
ReportReport
Posted on by 2

Hi All, looks like there's no OOTB method to simply automate the following logic in SharePoint, Teams or OneDrive:

  • When a bunch of PDF files get dropped into the "Starting Location" folder in SharePoint, move or copy each individual PDF file and disperse it to the folder with the matching "Destination" folder name in SharePoint.

  • If the folder with the matching name already exists then yes, move/copy the file to the matching folder. If there is no match do nothing.

Things to keep in mind:

  1. The Destination Folders are named exactly to match the PDF File names. The file names are always going to be 6 numerical digits in length

  2. The Files which need to be dispersed are always .PDF files and named example: 123456.PDF

  3. Corresponding Folders already exist and are nested with the same exact same 6-digit numeric convention as the PDF files intentionally to make this easy.

All we want to do is automate the actions in sequence: This is becoming really arduous. I have tried several flows and have done a bit of research and this isn't that easy.

Anyone able to contribute ideas?

Thanks

  • DB-06061845-0 Profile Picture
    2 on at
    Simple Move File functionality Not That Simple
     Hello can we please connect on this?@VictorIvanidze
  • VictorIvanidze Profile Picture
    12,478 on at
    Simple Move File functionality Not That Simple
     
    I'd like to inform you that I finally created a flow that fully fits your requirements. I did it just for fun.
    I spent about 6 hours total - definitely it's not a task for beginner ;)
     
    Not sure if I wish to publish the flow.
  • VictorIvanidze Profile Picture
    12,478 on at
    Simple Move File functionality Not That Simple
     
    the trigger "When a file is created or modified" cannot work when you move a file from one SharePoint folder to other one.
    You confirmed that fact.
     
    I guess the topic starter means exact such moving as he said "When a bunch of PDF files get dropped into the "Starting Location" folder".
     
    So it looks the flow you've offered just does not fit the topic starter's requirements.
     
     
  • Sam_Fawzi Profile Picture
    410 Super User 2025 Season 1 on at
    Simple Move File functionality Not That Simple
     
    It would be an issue if the requester is not handling the files that are not matching the folder names, because we will have files left in the folder. The recurrence will then need to process more files, and that will take longer. That's why I've suggested this trigger.
  • VictorIvanidze Profile Picture
    12,478 on at
    Simple Move File functionality Not That Simple
    Hey @SamFawzi-SmartSolutions, thanks for confirmation.
     
    Don't you think then that the only reliable way to create a flow according this requirement:
     
    "When a bunch of PDF files get dropped into the "Starting Location" folder in SharePoint"
     
    is using the "Recurrence" trigger?
     
  • Sam_Fawzi Profile Picture
    410 Super User 2025 Season 1 on at
    Simple Move File functionality Not That Simple
     
    Yes, that is correct. The trigger "When a file is created or modified"  may not fire if you move a file from one SharePoint folder to another within the same document library
  • VictorIvanidze Profile Picture
    12,478 on at
    Simple Move File functionality Not That Simple
     
    could you please confirm that the trigger "When a file is created or modified" does not work when you move a file from one SharePoint folder to other one?
  • Sam_Fawzi Profile Picture
    410 Super User 2025 Season 1 on at
    Simple Move File functionality Not That Simple
     
    thanks for pointing this out, I've updated the suggestion to match the new action name.
  • VictorIvanidze Profile Picture
    12,478 on at
    Simple Move File functionality Not That Simple
     
    the trigger you are recommending is deprecated. Do you know that?
  • Suggested answer
    Sam_Fawzi Profile Picture
    410 Super User 2025 Season 1 on at
    Simple Move File functionality Not That Simple
     
    here are 2 options for you to pick from
     
    Scenario 1: Less than 7 Destination Folders
    This approach uses nested conditions. While it can become unwieldy with a large number of folders, it's perfectly acceptable for a small, fixed set.
    1. Trigger: "When a file is created or modified"
      • Location: Your SharePoint Site
      • Library Name: The name of your document library
      • Folder: The "Starting Location" folder.
    2. Condition: Check if the file is a PDF
      • Condition: endsWith(toLower(triggerBody()?['{Name}']), '.pdf')
    3. Compose: Extract the 6-digit file name (without extension)
    • Inputs: substring(triggerBody()?['{Name}'], 0, sub(length(triggerBody()?['{Name}']), 4))
      • triggerBody()?['{Name}']: Gets the filename of the trigger file.
      • length(triggerBody()?['{Name}'] : Gets the length of the filename.
      • sub(length(...), 4) : Subtracts 4 from the filename length (to remove ".pdf").
      • substring(string, startIndex, length): Extracts a substring starting at index 0 and with the calculated length. This effectively removes the ".pdf" extension.
    Rename this action to "Compose - FileNameWithoutExtension" for clarity.
    1. Nested Conditions (for each destination folder):
      • Condition 1:
        • Left Value: outputs('Compose - FileNameWithoutExtension')
        • Operator: is equal to
        • Right Value: "123456" (Replace with the exact folder name)
        • If Yes:
          • SharePoint - Move file (or Copy file)
            • Site Address: Your SharePoint Site
            • File to move: triggerBody()?['{FullPath}']
            • Destination Folder: The full path to the "123456" folder (e.g., /Shared Documents/DestinationFolder/123456)
            • If moving and a file with the same name already exists: Choose your preference (Fail, Replace, or Rename).
        • If No: Add another Condition (Condition 2).
      • Condition 2:
        • Left Value: outputs('Compose - FileNameWithoutExtension')
        • Operator: is equal to
        • Right Value: "789012" (Replace with the exact folder name)
        • If Yes: Move file to the "789012" folder.
        • If No: Add another Condition.
      • Repeat this pattern for each destination folder (up to your limit of < 10).
      • If No (on the last condition): This means no matching folder was found. Leave this branch empty (or add a "Log to History" action for debugging, if desired).
    Scenario 2: More than 10 Destination Folders (Dynamic Path Building)
    This is the recommended approach for scalability. It leverages the file name to directly construct the destination path, avoiding nested conditions. This is far more efficient.
    1. Trigger: "When a file is created or modified"
      • Location: Your SharePoint Site
      • Library Name: The name of your document library
      • Folder: The "Starting Location" folder.
    2. Condition: Check if the file is a PDF
      • Condition: endsWith(toLower(triggerBody()?['{Name}']), '.pdf')
    3. Compose: Extract the 6-digit file name (without extension)
    • Inputs: substring(triggerBody()?['{Name}'], 0, sub(length(triggerBody()?['{Name}']), 4))
      • Rename this action to "Compose - FileNameWithoutExtension" for clarity.
    1. Compose: Build the Destination Folder Path
      • Inputs: concat(triggerBody()?['{Path}'], '/', outputs('Compose - FileNameWithoutExtension'))
    2. SharePoint: Move File
      • Use the "Move file" action.
        • File to move: Use triggerBody()?['{FullPath}'].
        • Destination Folder: Use the output from the previous Compose action.
    3. Configure Run After for Error Handling
      • If the move fails (e.g., if the folder does not exist), configure a "Run After" condition to handle any errors gracefully.

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May 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 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492