Search code examples
power-automatepowerapps

Renaming file in one drive from power automate flow


I have a power automate flow which gets an attachment from an email, and creates a new file in OneDrive folder with a new file name.

In my Action to Create a new file in OneDrive, This is what I have so far under the file name parameter:

concat('CounterpartyName',formatDateTime(utcNow(),''))

this gives me an ouput of this when I look in OneDrive:

CounterpartyName-2_23_2024 8_57_24

The file is not saved with the same suffix as the original attachment and the date formatting is not what I want.

Since I am working only with .csv, .xls, and .xlsx files this is what my output should look like:

CounterpartyName-02Feb24.csv  
OR
CounterpartyName-02Feb24.xls  
OR
CounterpartyName-02Feb24.xlsx

I am new to power platform so how could I alter that code to achieve those results? Any suggestions would help


Solution

  • Change to this for the date ...

    concat('CounterpartyName',formatDateTime(utcNow(),'ddMMMyy'))
    

    ... and as for the file extension, without knowing the name of your file, use a split() function with a period as a separator and then wrap that in a last() function to get the extension.

    Further to that, you can actually do everything without the need for a concat() function, like this ...

    enter image description here

    Expression 1 = formatDateTime(utcNow(), 'ddMMMyy')

    Expression 2 = last(split('Original File Name.xlsx', '.'))

    ... also notice the period between the two expressions.