• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 40
  • Last Modified:

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,
0
namerg
Asked:
namerg
  • 5
  • 4
1 Solution
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
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 CCEO J0rt3g4 Consulting ServicesCommented:
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
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
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 CCEO J0rt3g4 Consulting ServicesCommented:
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 CCEO J0rt3g4 Consulting ServicesCommented:
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
 
namergSystems AdministratorAuthor Commented:
Thanks a lot.
1
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Np, glad to help
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now