Rename files with specific pattern

Hello, I have the following code

Get-ChildItem -Path "C:\FileShares\Projects\G\C-00027" -Recurse | Where-Object {$_.name -like "DetailedEvents_C-00023_????_??_??_??????.xls"}

Open in new window


I do get the listing fine but i have to replace the C-00023 for C-00027 within the file. Inside this folder C:\FileShares\Projects\G\C-00027 i have over 1000 files and different subfolders. The original  file has the following pattern "DetailedEvents_C-00023_YYYY_MM_DD_hhmmss.xls"

Thanks for your help,
namergSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
I don't understand the problem.
Can you please try to explain a bit better?.
0
namergSystems AdministratorAuthor Commented:
Inside this folder "C:\FileShares\Projects\G\C-00027" i have subfolder and more than 1000 files with the following pattern "DetailedEvents_C-00023_YYYY_MM_DD_hhmmss.xls" I have to rename the files or replace the C-00023 for C-00027, so the 1000 files will look like "DetailedEvents_C-00027_YYYY_MM_DD_hhmmss.xls" Thanks,
0
Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
Get-ChildItem "C:\Fileshares\Projects\G\C-00027" |where{ $_.Name -match "00023"} | %{
    Rename-Item $_.FullName "$($_.DirectoryName)\$($_.Name.ToString().Replace("23","27"))"
}

Open in new window


Jose
1
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

namergSystems AdministratorAuthor Commented:
Just a little detail, had to add the -Recurse
0
namergSystems AdministratorAuthor Commented:
Jose, Can you post the code with -Recurse so i can give you the points ? Muchas Gracias.
0
Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
You mention you had one subfolder, with 1 doesn't need the -recurse with many and you would want to rename them all, you do.
Please mark the answer to close the question!.

jose
0
Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
Sure,
Get-ChildItem "C:\Fileshares\Projects\G\C-00027" -Recurse |where{ $_.Name -match "00023"} | %{
    Rename-Item $_.FullName "$($_.DirectoryName)\$($_.Name.ToString().Replace("23","27"))"
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
namergSystems AdministratorAuthor Commented:
Thanks a lot.
1
Jose Gabriel Ortega CastroEE Solution Guide - CEO Faru Bonon ITCommented:
Np, glad to help
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.