Skip to main content

Notifications

Power Automate - General Discussion
Answered

Creating a file: if it exists do not create it / if it does not exist create it

(0) ShareShare
ReportReport
Posted on by

Hello everyone

I would like to know how to get the answers to a form:
If the person has never filled in the form it creates a folder with their name on it
and if the person comes back and fills in the form again, the file is not created.

This is what I currently have as a flow :

 

Charline74_0-1627894972290.png

 

Categories:
  • eric-cheng Profile Picture
    eric-cheng 5,171 on at
    Re: Creating a file: if it exists do not create it / if it does not exist create it

    Hi @Anonymous ,

     

    Wow, I had to re-read what I typed from last year.

     

    I used the variable as a flag because I think in your original post, you wanted to not recreate the file if the folder with the person's name exists.  This is one of many ways of achieving the goal and allows you to place your business logic/actions outside of the loop if required.

     

    You could also use an expression to get the count and use a condition as well.

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

  • Re: Creating a file: if it exists do not create it / if it does not exist create it

    @eric-cheng 

     

    Just question : why in the first condition if yes we set a variable to true ? What the goal ? 

  • VSTrath Profile Picture
    VSTrath 25 on at
    Re: Creating a file: if it exists do not create it / if it does not exist create it

    @eric-cheng This is very helpful but not quite working for me.

     

    My scenario is slightly different. I want users to be able to submit a form and for these details to go into a list item on Sharepoint. This part is done. But in the form there is an option to upload documents. I want a flow that creates a folder for this list item, adds these documents to it and then adds a link to the folder location in the list item column called 'Folder'. This is so that the person assigned to respond to this task can click on the folder location easily, using the list essentially as a dashboard.

     

    However, instead of triggering this flow when the form is submitted I am attempting to replicate this for when a new list item is added. This is because there will be occasions when we need to manually add a list item within Sharepoint rather than it come through the form submission. I still want the folder to be generated automatically to ensure consistency in folder naming but the actual files will need to be added manually to the folder in this case.

    So this is what I'm thinking:

     

    1. When an item is created

    2. Get item

    3. Create new folder

    4. Create file

    5. Create sharing link for a file or folder

    6. Update list item

     

    However, I don't know what to put into steps 4 - 6. Wondered if you could expand on the step you posted about below and maybe offer some other pointers? I haven't included the set variable etc steps because I don't think I need these but may be wrong. Many thanks.

     

    VSTrath_0-1632407484295.png

     

     

  • Re: Creating a file: if it exists do not create it / if it does not exist create it

    @eric-cheng 

    Is this the name of the folder I want to create or the name of the folder where responses are sent? Do you have an example?

  • eric-cheng Profile Picture
    eric-cheng 5,171 on at
    Re: Creating a file: if it exists do not create it / if it does not exist create it

    Hi @Anonymous ,

     

    The value/field with the folder name

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

  • Re: Creating a file: if it exists do not create it / if it does not exist create it

    @eric-cheng  

    Thank you for your answer, just a question what do you mean by Forms field ? 

     

    Is this the form id link ? 

  • Verified answer
    eric-cheng Profile Picture
    eric-cheng 5,171 on at
    Re: Creating a file: if it exists do not create it / if it does not exist create it

    Hi @Anonymous ,

     

    Try the below flow and assume Q1 is the name of the respondent 

     

    1) Initialize a boolean variable and set it to @false

    ericcheng_0-1627911410419.png

     

    2) Use a Get Files (properties only) action to get all files and folders from your document library.  Add an ODATA filter FileLeafRef eq 'Q1' (replace Q1 with your Forms field).  FileLeafRef is the internal name for name in SharePoint.

     

    ericcheng_4-1627911750983.png

     

     

    3) Loop through each returned file and add a condition for IsFolder = true.  If true, it means a folder was found with the name.  Set the boolean variable to @false

    ericcheng_2-1627911565152.png

    4) Exit the loop and add another condition to check your boolean variable.  If false, it means no folder was found and you can proceed to create a folder and add a file (same logic that you already have).

    ericcheng_3-1627911625652.png

     

    Run for first form submission which will  create a folder and file

    ericcheng_7-1627912220826.png

     

    Run for second submission with same name which will skip

    ericcheng_8-1627912262441.png

     

     

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

  • Re: Creating a file: if it exists do not create it / if it does not exist create it

    Hi @eric-cheng 

     

    How to make sure the file isn't created again when the user submits the form the second time

  • eric-cheng Profile Picture
    eric-cheng 5,171 on at
    Re: Creating a file: if it exists do not create it / if it does not exist create it

    Hi @Anonymous ,

     

    Can you clarify whether you are asking:

     

    1) Why the file isn't created when the user submits the form the second time

    2) How to make sure the file isn't created again when the user submits the form the second time

     

    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

    Connect on LinkedIn

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,691

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 65,019

Leaderboard