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
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (1,890)