1

I am trying to write a powershell script which go to specific folder which have multiple folders containing Excel file. File name is as example 1_RIM_Reports_201510.xlsx 2_Rim_Reports_September.xlsx

Now I want to change replace the word RIM with NIR how can i do that for multiple files.

1_NIR_Reports_201510.xlsx 2_NIR_Reports_September.xlsx

Get-ChildItem $directory -Recurse |

    Rename-Item { $_.name -replace '*RIM*.xlsx', '*NIR*.xlsx' }

1 Answer 1

3

If your string always have the the underscore _ before and after you can simply use this:

Get-ChildItem $Directory -Recurse | 
Foreach-Object { Rename-Item $_.FullName ($_.FullName -replace "_RIN_","_NIR_")}

Otherwise you need to use Regular Expression, if this is the case let us know

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks it helped !! :)
how do you change the words in file if the word say RIM OLD Reports for consolidation how can i chagne it to RIM OLD Reports for consolidation?
Change the first section (before the comma) to any chars you like and the end section (after the comma) to the result you want "_RIN_","_NIR_"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.