cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jared_Simon
Frequent Visitor

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 III
Super User III

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 III
Super User III

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
Frequent Visitor

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
Frequent Visitor

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 III
Super User III

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

Jared_Simon
Frequent Visitor

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 III
Super User III

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', ''))

Jared_Simon
Frequent Visitor

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 III
Super User III

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

Jared_Simon
Frequent Visitor

Thank you @Paulie78 

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

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (18,136)