Special characters like brackets and parentheses, exclamation marks, or symbols (e.g., #, &, ****) in file names can disrupt workflows, break URLs, or cause errors in systems like SharePoint or cloud platforms. For example, a file named “Sales_Report(Q3).pdf” might fail to sync due to the parentheses, or “Invoice#123.xlsx” could corrupt a JSON or XML export. These unwanted characters from a string also reduce readability and consistency. Manual renaming is tedious, especially when dealing with multiple characters across hundreds of files. Power Automate solves this by automating the removal of specific characters using expressions to remove symbols, ensuring compatibility and standardization.
Automating this process with Power Automate or PowerShell ensures efficiency and accuracy. Use the replace function or regex (regular expressions) to remove characters from a string dynamically. For example:
Replace spaces with underscores using replace(triggerBody()?['Name'], ' ', '_')
.
Strip trailing spaces or leading and trailing symbols like commas or quotes.
Delete numbers with replace(outputs('FileName'), '\d', '')
.
This automation reduces manual effort, eliminates errors, and standardizes names (e.g., converting “File*Name!!.txt” to “FileName.txt”). It’s ideal for document library management or preparing files for automation pipelines.
Trigger: Start with a trigger like “When a file is created/modified” in SharePoint or OneDrive.
Extract File Name: Use the “Get File Properties” action to retrieve the original string.
Remove Characters: Apply Power Automate expressions like replace()
or substring()
:
Remove specific characters: replace(outputs('FileName'), '[#&()]', '')
deletes #, &, and parentheses.
Trim spaces: Use trim()
to eliminate leading and trailing spaces.
Handle Complex Cases: For advanced needs, use regex patterns (e.g., replace(outputs('FileName'), '[^\w.]', '')
) to strip all non-alphanumeric characters except periods.
Remove brackets and parentheses:
Copy
replace( replace(outputs('FileName'), '\(', '' ), '\)', '' )
Delete numbers: Use replace(outputs('FileName'), '\d', '')
to remove numbers from filenames.
Replace multiple characters: Create an array of characters (e.g., ['!', '?', '#']
) and loop through them with Apply to Each, replacing each with an empty string.
Retrieve the File Name: Use “Get File Content” to access the original string.
Clean the String:
Remove specific character: replace(outputs('FileName'), '/', '')
deletes slashes.
Substring: Extract parts of the name (e.g., substring(outputs('FileName'), 0, 10)
) to limit the number of characters.
Advanced Cleaning: For trailing spaces or special characters like quotes, use nested replace()
actions. For example:
Copy
replace( replace(outputs('FileName'), '"', '' ), '''', '' )
This removes double quotes and single quotes.
Test with Sample Data: Run the flow on a file named “Data_2024!!.csv” to ensure it becomes “Data_2024.csv”.
Use Transcripts: Check the transcript for errors, such as incorrect regex patterns or failed replace function logic.
Handle Edge Cases: Add conditions to skip files without characters to remove or log issues for manual review.
For highly complex scenarios, combine Power Automate with PowerShell or Power Query:
PowerShell: Use scripts like Get-ChildItem | Rename-Item -NewName { $_.Name -replace '[^\w]', '' }
to remove unwanted characters in bulk.
Power Query: Transform filenames using Text.Remove([Name], {'#', '(', ')'})
in Excel or Power BI.
This is useful for cleaning table of contents entries or preparing data for JSON/XML exports.
Bulk Renaming: Use Apply to Each loops to process multiple characters across thousands of files in SharePoint or OneDrive.
Integration: Feed cleaned filenames into downstream systems like CRM or ERP using JSON or APIs. For example, sanitize filenames before input or uploading to a document library to ensure compliance.
Automate removing unwanted characters from a string in Power Platform using regex or replace function to remove specific characters like brackets, quotes, parameter, numbers, or spaces. With PowerShell or Power Query, extract substrings, trim leading/trailing spaces, and clean filenames for document libraries. Use arrays or regular expressions to delete multiple characters, ensuring seamless automation.
For ready-to-use Dashboard Templates: