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

Community site session details

Session Id :
Power Automate - Using Flows
Answered

Get a part of a folder path of SP list to copy a file from one library to another

(0) ShareShare
ReportReport
Posted on by 251
Hi!
 
So what I want to do is when a file in private library is approved, copy that file with all metadata into a public library. The flow I have created was this one:
 
That is the flow I have. The thing is in create file i get the dynamic content "Carpeta" wich is this column on a list:
 
 
But in that path, the highlighted part I don't need it, and to copy the file to there I cannot use this dynamic content. I would need to split all the parts and get split 1, 2 and possibly 3 (Not every file will have 3 folders). So the first part will be ignored.
 
What could I use do? Is there any other way to do it?
I have the same question (0)
  • Suggested answer
    Tomac Profile Picture
    3,252 Moderator on at
    Get a part of a folder path of SP list to copy a file from one library to another
     
    When referencing this value, use the following expression:
    replace(items()['Carpeta'],'Documents compartits/','')
    This will remove the "Documents compartits/" at the beginning of the value, leaving you with the remaining path.
     
    Just be sure that the dynamic content matches the correct value from your flow.
  • Charlie Martharper Profile Picture
    251 on at
    Get a part of a folder path of SP list to copy a file from one library to another
    Hi @Tomac,
     
    Do you mean like this?
    It returns me this error:
    Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The template action 'Create_file' at line '1' and column '2969' is not valid: "The template language function 'items' must have at least one parameter.".'.'
     
    Sorry for my bad understanding, but I don't know where to add that :(
  • Tomac Profile Picture
    3,252 Moderator on at
    Get a part of a folder path of SP list to copy a file from one library to another
    You'll need to change the dynamic content in my code sample ( the 'items()['Carpeta']' bit) to match your flow's dynamic content for that field. This will resolve the error.
  • Charlie Martharper Profile Picture
    251 on at
    Get a part of a folder path of SP list to copy a file from one library to another
     
    Could you send a screenshot and explain step by step? I still don't know how to do it. 
    So you mean to create a function with all the code? Then how should I add the other part of the flow to that?:
    replace(items()['Carpeta'],'Documents compartits/','')
  • Vejai SH Profile Picture
    519 on at
    Get a part of a folder path of SP list to copy a file from one library to another
     
    if you are using Items in loop you have to use the reference of the current item.
    replace(items('Apply_to_each')?['Carpeta'], 'Documents compartits/', '')
     
    if Item then, it will refer to current item
    replace(item()?['Carpeta'], 'Documents compartits/', '')
     
    You can find the explanation here
     
    Thanks, 
    Vejai SH  
     
    Please mark as answer if my suggestion helps you
  • Charlie Martharper Profile Picture
    251 on at
    Get a part of a folder path of SP list to copy a file from one library to another
    Hi!
     
    Well what I have in that path is 2 dynamic content: "Àmbit" which get which library will go, one fixed term which is "Ciutadania" (is a folder) and finally "Carpeta" that is the rest of the folders.
     
    The Àmbit could be more than one choice, and depending which choices they get, it will sent to one or more libraries so then I think it creates an apply to each.
    So I have an Apply to each for "Àmbit" and Apply to each (2) for the "Carpeta".
     
    I don't think it will happen a lot but it could happen to be in more than one Àmbit.
     
    So maybe I should use the second option you gave me. 
     
    The thing is, how I add that to replace the first part of the Carpeta? I should create the expression there with all the data?
     
    Thanks!!
  • Vejai SH Profile Picture
    519 on at
    Get a part of a folder path of SP list to copy a file from one library to another
     
    It will be like this if you "Peek code" your action
    /@{items('Apply_to_each')?['Àmbit']}/Ciutadania/@{replace(items('Apply_to_each_2')?['Carpeta'], 'Documents compartits/', '')}
     
    Thanks, 
    Vejai SH  
     
    Please mark as answer if my suggestion helps you
  • Charlie Martharper Profile Picture
    251 on at
    Get a part of a folder path of SP list to copy a file from one library to another
    Hi Vejai,
     
    Thanks for being so specific, I really need that but that "Peek Code" is not working 😥
     
    I tried changing it a little bit but there is no difference in the result. Because when I delete "Carpeta" from the path, the "apply to each (2)" disappears somaybe that's the reason.
     
    What changes should I apply in the "Peek code" having this issue?
  • Suggested answer
    Tomac Profile Picture
    3,252 Moderator on at
    Get a part of a folder path of SP list to copy a file from one library to another
     
    I'm back in for the morning. 
     
    So I've noticed in your screenshots that the input for your top level Apply To Each has changed. It should always be "value" from the Get Items action. When you do that, the Carpeta expression shouldn't cause another loop to be inserted.
     
    My recommendation is to use this in the Folder Path section of your Create File action:
    /Biblioteca HJ23/Cuitadania/@{replace(item()?['Carpeta'], 'Documents compartits/', '')}
     
    Note that if the folder you're targeting doesn't exist, it may give you an error about that. There is a way to dynamically create folders from a path structure but it's super complicated and not for beginners.
  • Charlie Martharper Profile Picture
    251 on at
    Get a part of a folder path of SP list to copy a file from one library to another
    Hi again Tomac! Glad to see you back!
     
    One thing I see when adding that on expression, the part of 'Carpeta' doesn't appear in get items as a dynamic content.
     
    Look i added how you told me: 
    replace(item()?['Carpeta'], 'Documents compartits/''')}
     
    The thing is it doesnt work that expression:
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    The first part 'Biblioteca' gets the library, "ciutadania" is the main folder and then, I cannot get correctly the last part.
    The thing is that 'Carpeta' is not in the Get items but yes in the trigger, look:
    "Cami de la carpeta" and "Carpeta" it's the same path, but one is in trigger and other as an action.
     
    How would this change your code? The folders are all created and will just have to follow the path, its the same structure of folders the public and the private library I am copying the 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

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 493 Moderator

#3
Expiscornovus Profile Picture

Expiscornovus 246 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Restore a deleted flow