Creating a flow to rename a file when it's created in a folder, however the file name has a random string at the end of the name and I'm not sure how to compensate for that. I've tried searching but don't really know how to phrase that search term. Any help would be greatly appreciated, thank you.
What does your flow look like and what are you trying to do after the file is created?
Why do you need to rename it after creating? You can set a custom name during the creation phase.
Basically trying to set it up as follows:
File comes in with Name_123.xls
Rename to NewName_Date.xls
Move original file to another folder
So right now I have it setup on file creation in folder (probably a better way), get file content (believe that's correct), create file.
One thing to note, you don't want the flow looking in the same directory for new files as the create file action is using. This would result in an infinite loop.
Here is a very basic example of how this can work.
The highlighted part is the "File Identifier" dynamic content from the "When a file is created..." action.
This flow gets the item created in the "New Files Here" folder. It creates a copy of it with the specific file name (you can use dynamic content or variables here to add a date) and drops it into the "Flow Created Files Here" folder. This step avoids a loop by dropping it in "New Files Here Folder". It then moves the original file that triggered the flow using its File Identifier to the "Old Files Here" folder.
Types as in xlsx vs docx (etc)?
There are 2 ways to handle this. With a conditional (yes/no branch) or a switch.
The easiest way is a conditional:
In this example, if the file has .xlsx in the name, the yes branch will run. If not, the no branch. You can then nest additional conditionals in the no branch to check for other file extensions.
The other way to do it is via a switch. The annoying part here, the switch can only check exact values. It does not support expressions in the cases. To get around this, you can "split" the file name into a variable and then check for that in the case.
Looks good with 1 exception. Your "create file" path and "when a file is created" path are the same. This could cause an infinite loop of the create file triggering itself.
Yeah I got an error for that in the flow but it didn't make sense until you just said something.
I do have a question though, the process is creating the file as intended however it is moving the new file and not the old file.
Using the "File Identifier" dynamic content under the "When a file is created..." header fails inside the "Move File" action?
What error does it give?
I'm an idiot, I was trying to copy it to the same folder but I didn't catch it until I read the error.. it works, thank you!
The destination path cannot be the same as the source object itself.
Keep up to date with current events and community announcements in the Power Automate community.
A great place where you can stay up to date with community calls and interact with the speakers.
Check out the latest Community Blog from the community!