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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Sharepoint Copy File Name
Power Automate
Unanswered

Sharepoint Copy File Name

(0) ShareShare
ReportReport
Posted on by

Morning, 

 

I have a flow that works but looking to add an incremental number to the end of the file name every time the run flows. The file name will be standard "Weekly Handover" but i want to add a counting number to the end of the file name that will come out of a "Initialise Variable" into a "Increment Variable" output. 

I just get an error as soon as i try to type any sort of free text into the "Enter Custom Value" box

H

Jay466_0-1710230853271.png

 

  

Categories:
I have the same question (0)
  • Andrew_J Profile Picture
    1,962 Moderator on at

    @Jay466 

     

    You need to intialise a variable at the start of your flow.  Then before you need to rename the file set the variable, I would suggest that you create a new file using that option.  Also try using the classic UI it might work better that way as the new UI is a little buggy.

     

    Happy to advise further if you can send me an image of your flow.

     

    Regards,

     

    Andrew

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @Jay466 There are two ways you could approach your flow.

     

    1) Append the Current Date to the End of your File Name
    I'm assuming you only run this flow once a week based on the name of the file.

     

    2) Get the last file created and take the number that has been appended to the end of the file and increase that number by one. 

     

    I'm using the Classic Designer for my demo below—you'll need to switch to the Classic Designer to follow along. Both of these options will start the same. Remember to rename your actions to keep your flow organized.

    Get File to Copy

    You'll need a Get file content or Get file content using path action in your flow to get the file content of the file you want to copy. I'm assuming you have a template file you want to copy. However, if you want to use the content from the previously created file—a few adjustments will need to be made to this flow. 

     

    Select your Site Address and your file.

    creativeopinion_5-1710688937213.png

     

    Option 1: Append Current Date to the End of File Name

    This would be the easiest to implement as you just need to create a new file with the file content from your template file and append the current date to the end of the file name.

    creativeopinion_14-1710689921433.png

     

    Get Today's Date

    Whenever you are using dates and times in your flow—it's best practice to use a Convert Time Zone action. In the base time field, insert the utcNow() expression.

     

    Source Time Zone: Coordinated Universal Time

    Destination Time Zone: Local Time Zone

    Format String: Round Trip

    creativeopinion_6-1710689516274.png

     

    Add a Compose action (this is optional). However, I like to use Compose actions to test out the filename syntax to ensure it's exactly how I want it before I add any additional actions to my flow. 

     

    Add your static text to the Compose action and a space (or underscore—customize this to suit your needs). Add an expression and insert the formatDateTime() function. 

    creativeopinion_7-1710689554559.png

    Click on the dynamic content tab and insert the Converted Time dynamic content. 

    creativeopinion_8-1710689669227.png

    Add a comma and single quotes and a date/time format pattern. Customize the date/time format pattern to suit your needs.

    creativeopinion_9-1710689703209.png

    Don't forget to add the file extension to the end of your file name. creativeopinion_10-1710689749408.png

    Run a test. Review the output of the Compose action and ensure it's what you are expecting. If not, go back and edit the Compose action until the Compose action outputs the file name you expect.

     

    creativeopinion_12-1710689845215.png

     

    Create the File

    Add a Create File action to your flow. Select your site address and folder path. In the File Name field, insert the output from the Compose action above. In the File Content field, insert the File Content dynamic content.

     

    creativeopinion_13-1710689909607.png

    Run a test. 

    creativeopinion_15-1710690036886.png

     

    Option 2: Get Last File Name and Increment by 1

     

    Get Last File Created Details

    Add a Get Files (properties only) action to your flow. Fun fact, this action returns files and folders. To limit this action to files only, you'll need to use a filter query:

    FSObjType eq 0

    You can use a 1 to return folders only. 

     

    To get the last created file, you'll need to define an orderBy query:

    Created desc

    This will order the files returned by Created date in descending order.

     

    Also, since you only need the last file created you can limit the number of files returned by specifying a Top Count. Enter 1 into this field. 

    creativeopinion_3-1710688322278.png

     

    The Get files (properties only) action will always return an array of items even if it's a single item. To get the details of the item, you'll need to use an expression. Add a Compose action and insert an expression. Use the first() function. 

     

    creativeopinion_1-1710688192929.png

    Click on the Dynamic Content tab and insert the value dynamic content from the Get files (properties only) action. 

    creativeopinion_2-1710688208565.png

    Run a test. Review the output of the Compose action. This action should display the details of the last file created.

    creativeopinion_4-1710688344005.png

    Scroll down until you see the file name without an extension. The red text between the double quotes is the dynamic content key which is what we'll need. 

    creativeopinion_17-1710690285567.png

    Click on the dynamic content label of the Compose action to edit the expression. Add the following to the end of the expression:

    ?['{Name}']

    This expression will now return the file name (without extension) only.

    creativeopinion_18-1710690345143.png

     

    Get the Number

    Add another Compose action to your flow and insert an expression. Use the split() function.

    creativeopinion_19-1710690422966.png

    Insert the Output from the Compose action storing the file name.

    creativeopinion_20-1710690466200.png

    Add a comma and single quotes. Between the single quotes, enter your separator that appears before the number you want to increment. In my case it's an underscore—so I'll enter an underscore. 

    creativeopinion_21-1710690528979.png

    Run a test. The split() function will split the file name by the separator. The output is an array. Since the number is the last item in the array we need to edit the expression to return the number only.

    creativeopinion_22-1710690572392.png

    At the beginning of the expression insert the word last with an opening parenthesis.

    creativeopinion_23-1710690632455.png

    Go to the end of the expression by pressing the down arrow key and enter a closing parenthesis. Don't forget to press Update.

    creativeopinion_24-1710690684497.png

     

    Run a test. Review the output of the Compose action. It should only return the number.

    creativeopinion_25-1710690730109.png

     

    Increment the Number

    Now that you have the number you want to increment, you'll need to increment the number by 1. First you'll need to convert the string of text to an integer. Wrap the entire expression in the int() function. At the start of the expression enter the word int with an opening parenthesis. 

    creativeopinion_28-1710690942798.png

    Go to the end of the expression by pressing the down arrow key and enter a closing parenthesis.

    creativeopinion_29-1710690963159.png

    To increment the number by 1, you'll need to use the add() function. Go back to the start of the expression by pressing the up arrow key and enter the word add with an opening parenthesis.

    creativeopinion_30-1710691016663.png

     

    Go to the end of the expression by pressing the down arrow key and enter a comma, a 1 and closing parenthesis. Don't forget to press Update.

    creativeopinion_31-1710691031543.png

     

    Run a test. Review the output of the Compose action. 

    creativeopinion_32-1710691060493.png

     

    Compose the File Name

    I've renamed the number compose action to New File name and added static text as well as a file extension. 

    creativeopinion_33-1710691172166.png

    Run a test. Review the output of the Compose action.

    creativeopinion_34-1710691201719.png

    Create the File

    Just like the previous option. Add a Create File action. Insert the output of the Compose action above into the File name field. 

    creativeopinion_35-1710691232218.png

    Run a test. 

    creativeopinion_36-1710691333581.png

     

     

    For more flow troubleshooting tips—check out this YT Tutorial: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows

     

    IN THIS VIDEO:

    ✅ How to troubleshoot a false Condition action result

    ✅ How to get dynamic content when it isn’t selectable from the list of dynamic content

    ✅ How to troubleshoot an Apply to Each action that isn’t looping through

    ✅ How to troubleshoot a skipped Apply to Each action

    ✅ How to troubleshoot a Filter Query

    ✅ How to use a SharePoint yes/no column in a Filter Query

    ✅ How to use Compose actions to troubleshoot a Power Automate flow

    ✅ How to troubleshoot multiple emails being sent

    ✅ How to troubleshoot multiple Teams messages being sent

     

    Hope this helps!

    If I helped you solve your problem—please mark my post as a solution ✅.
    Consider giving me a 👍 if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram

     

     

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

Forum hierarchy changes are complete!

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

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard