cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jared_Simon
Helper I
Helper I

remove text from filename

I have a flow that saves email attachments to sharepoint library. some attachments comes with an extra text... for example - Sales_Data_21-03-1982KNR.PDF - sometimes they come without it. is there a way I can ensure that to save such files without KNR in filename? basically I would like to replace "KNR" with "no space" so that its omitted... thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

If you want to retain the original case, you could do multiple replace actions like this:

replace(replace(replace(items('Apply_to_each')?['Name'], 'knr', ''), 'KNR', ''), 'Knr', '') 

This will leave the original filename untouched but remove "knr", "KNR" and "Knr". I have an article on my blog for proper case:

How to create Proper Case Strings in Power Automate 

View solution in original post

11 REPLIES 11
Paulie78
Super User
Super User

Use an expression like this:

replace(outputs('Filename'), 'KNR', '')

You will need to replace the outputs('Filename') with whatever dynamic content contains your filename.

Jared_Simon
Helper I
Helper I

Hi @Paulie78 

 

the attachment name - when I copy to notepad shows this - @{items('Apply_to_each')?['Name']}

 

but when I use the code you suggested, I get "expression is invalid" error...

 

I used below...

 

replace(items('Apply_to_each')?['Name'], 'knr',")

 

could you help me correct it please?

replace(items('Apply_to_each')?['Name'], 'KNR',")

 

 

Jared_Simon
Helper I
Helper I

Hi @Paulie78 I got it to work with the following.... but it passes files with knr (lower case) - is there a way to fix that?

 

replace(items('Apply_to_each')?['Name'], 'KNR', '')

Paulie78
Super User
Super User

replace(toLower(items('Apply_to_each')?['Name'], 'knr', ''))

Jared_Simon
Helper I
Helper I

it fails with following...

 

InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '3175': 'The template language function 'toLower' expects one parameter: the string to convert to lower casing. The function was invoked with '3' parameters. Please see https://aka.ms/logicexpressions#toLower for usage details.'.

 

is there a way to modify your original code to include both "KNR" & "knr" ?

Paulie78
Super User
Super User

Sorry, put the brackets in the wrong place and didn't test it, try this:

replace(toLower(items('Apply_to_each')?['Name']), 'knr', '')

replace(toLower(items('Apply_to_each'))?['Name'], 'knr', '')

or

toLower(replace(items('Apply_to_each')?['Name'], 'knr', ''))

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.
Jared_Simon
Helper I
Helper I

Thank you @Paulie78 and @VictorIvanidze 

 

as the resultant filename becomes fully lowercase - I used toUpper() in the file creation time to change it....

I wish there was a "toProper" function to capitalize only first letters of the file name words (eg: Sales Data 21-02-2012)

 

but the main objective is accomplished! - Thanks a ton!

 

Paulie78
Super User
Super User

If you want to retain the original case, you could do multiple replace actions like this:

replace(replace(replace(items('Apply_to_each')?['Name'], 'knr', ''), 'KNR', ''), 'Knr', '') 

This will leave the original filename untouched but remove "knr", "KNR" and "Knr". I have an article on my blog for proper case:

How to create Proper Case Strings in Power Automate 

Jared_Simon
Helper I
Helper I

Thank you @Paulie78 

Could you mark @Paulie78 's answer as a solution?

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,879)