web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Excluding Folders From...
Power Automate
Answered

Excluding Folders From "When a file is created" Using Sharepoint

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello,

 

I am trying to create a flow that when a file is added it creates a main folder with 3 folders inside then moves the original document. So far i have managed to get the flow to get the file name of the file added then create a folder with the file name and then a file within it. Unfortuatley because the "When an item is created or modified" trigger it creates an infinte loop as whenever a file is added in the library do this. Is there a way to stop this or exclude folders from the trigger?

 

Thanks in advance.

Categories:
  • MarkStokes Profile Picture
    561 on at

    You can't filter on that trigger.

     

    The way I normally get around this is to have a Run Flow yes/no field on the list/library. The default is YES and then the first action the Flow performs is to set that fella to No. Then it goes on and processes it as you wish.

     

    The action of setting it to No will also trigger the Flow to run, but you have a condition in your Flow to ONLY CONTINUE IF RUN FLOW IS SET TO YES.

     

    This way you can **bleep** that infinite loop in the bud.

     

    - Mark

  • svijay_001 Profile Picture
    Microsoft Employee on at

    You could use a condition and filter out the files/folder based isFolder property.

     

    You can branch out perform action only files when IsFolder Property is set to false. 

     

    001.png

  • Brad_Groux Profile Picture
    4,556 on at

    If you could provide an expanded screenshot of your Flow and steps, and of any detailed error messages you're receiving we could likely better assist you.

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    So this is what i currently have. I am using the .txt files to create new folders for me then removing them but everytime a new one is created as you can probably tell it restarts the flow and creates an infinite loop

    Capture3.PNGCapture4.PNGCapture5.PNG

  • Verified answer
    v-lin-msft Profile Picture
    728 on at

    Hi @Anonymous,

     

    You could use Send an Http request to SharePoint action to create your folder and the subfolder.

    It can avoid trigger your flow multi times and you can not to delete these files:Annotation 2019-06-17 163900.png

     

    Method: POST

    Uri:

    _api/Web/GetFolderByServerRelativeUrl('/sites/SiteName/LibraryName')/Folders

    Headers: 

        Content-Type   application/json; odata=verbose

     

    Accept   application/json; odata=verbose

    Body:

    { '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': '/sites/SiteName/LibraryName/New Folder/SubFolder1'}"}

     

    Besides, about your question Is there a way to stop this or exclude folders from the trigger?

    Yes, you can add a condition that judges the file whether is a folder under the trigger:

    -If yes, do the next steps;

    -If no, end the run.

    Annotation 2019-06-17 172038.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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

     

     

    Hi @v-lin-msft,

     

    Do you know if it possible to create the folders using the Integrated dynamics as the name? as every file that comes in needs to have a folder created with the name of the file then 4 folders created inside of it. also if im using the "When a file is created" wouldn't the flow start everytime a new folder is created? Or do i add the "Check if folder" before trying to create the new ones?

     

    Edit: Tried using the flow shown above however i am getting the following error.

    Capture6.PNG

  • v-lin-msft Profile Picture
    728 on at

    Hi @Anonymous,

    If you create folders using this method, you can dynamically define the folder name, as shown by the red line in the image. Similarly, you can define the names of subfolders in the same way.

    Annotation 2019-06-18 093305.png

     

    Since the method you used to create folder before need to create a new file, if you use the "When a file is created", it will trigger the flow every time. Realistically, the structure of your stream will trigger multiple times even if you add a condition to determine whether it is a folder or not.

     

    As the problem that you met shown as your screenshot, you could share your flow configuration to us.

     

    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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    This is the Flow that is currently giving me the error i cannot figure out why and it's starting to get really frustrating.

    Capture7.PNG

  • v-lin-msft Profile Picture
    728 on at

    Hi @Anonymous,

     

    Could you show a screenshot of the error message, please?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    All sorted now accidently copied an extra ' and } which killed the whole thing haha, typical coding. Everything is working as expected now thanks for all the help!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 425

#2
11manish Profile Picture

11manish 323 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard