New to PAD, so I'm sorry if this is a stupid question, but...
I'm trying to create a flow that removes a specific piece of text from a file name for 1,200+ unique files in a folder.
I created:
(1) a flow that uses the 'Get files in folder' to pull all the files within the folder (with the path included) and create a variable (%Files%) with the full list of each file path as its own line #.
(2) a 'For each' loop that will go through each file in the folder, and within the loop:
(2a) a 'Get file path part' action from the first item in the %Files% list that pulls the file name (%FileName%)
(2b) a 'Rename file(s)' action with the file path and %FileName% that removes the text from the file name.
However, when I run the flow, it pulls the first file from the first path on the %Files% list and then errors out because it searches for the same file (that it has already renamed) on the second iteration of the loop. How do I get it to move to the next item/file path in the list for the %Files% variable?
Any ideas would be appreciated.
Solved! Go to Solution.
Thanks for the answers @MichaelAnnis and @Henrik_M . I figured it out last night after trying @MichaelAnnis's code and a bit more internet searching. I was definitely overthinking the code on this one. Turns out the loop does move to the next list item on each iteration naturally, but it does it in the %CurrentItem% variable produced by the loop rather than the %Files% list variable created in the 'Get files in folder' action. If I tell it to rename the file for %CurrentItem% it will cycle through each file in the folder and rename it. I've attached the code I ended up with.
@MichaelAnnis: Your code essentially does the same thing, but it took me a while to realize it. You set me on the path to figuring out why it worked though, so thanks again for that.
I would try replace text:
For each CurrentItem in %Files%
Set Variable %filename% to %CurrentItem%
Replace Text %WhatToFind% with %""% in %filename% to %newfilename%
Rename %filename% to %newfilename%
End
%""% is the format for "Replace with nothing". So, this would say, give me the filename, replacing that with nothing gives me a new file name. Rename my file from old file name to new file name.
Best of luck!
It sounds strange that it handles the same file twice.
Can you share your code? 🧐
Thanks for the answers @MichaelAnnis and @Henrik_M . I figured it out last night after trying @MichaelAnnis's code and a bit more internet searching. I was definitely overthinking the code on this one. Turns out the loop does move to the next list item on each iteration naturally, but it does it in the %CurrentItem% variable produced by the loop rather than the %Files% list variable created in the 'Get files in folder' action. If I tell it to rename the file for %CurrentItem% it will cycle through each file in the folder and rename it. I've attached the code I ended up with.
@MichaelAnnis: Your code essentially does the same thing, but it took me a while to realize it. You set me on the path to figuring out why it worked though, so thanks again for that.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.