I have a root dir that has hundreds of folders in it that are named with a legacy company name and date format, I want to rename these files within all the folders with PowerShell, I have been trying all day but no luck thus far I’m a noob to scripting, only ever normal have to do login scripts and easy stuff.<\/p>\n
I need to maintain the date format on the files so they need to look like example new_businessname06092021.csv<\/p>\n
Get-ChildItem –Path \"C:\\temp\\AMLReports\" -Recurse -Filter *.csv\nforeach($file in Get-ChildItem $SomeFolder)\n{\n $newname = ([String]$File).Replace(\"oldbuisnessname\",\"newbusinessname\")\n Rename-item -Path \"C:\\temp\\AMLReports\\Renamed\" $File $newname\n}\n\n<\/code><\/pre>\n
Advertisement
Help appreciated
<\/p>","upvoteCount":3,"answerCount":19,"datePublished":"2021-06-09T02:38:06.000Z","author":{"@type":"Person","name":"milesit","url":"https://community.spiceworks.com/u/milesit"},"acceptedAnswer":{"@type":"Answer","text":"
how about like so?<\/p>\n
$files = Get-ChildItem \"C:\\temp\\AMLReports\" *.csv -Recurse\n\nforeach($file in $files){\n $newname = $file.name -replace \"oldname\",\"newname\"\n Rename-item $file.fullname -NewName $newname -verbose\n}\n<\/code><\/pre>\nTest it before<\/strong> you let it lose in your prod environment.<\/p>","upvoteCount":0,"datePublished":"2021-06-09T02:57:02.000Z","url":"https://community.spiceworks.com/t/powershell-file-rename-recuse-help-needed/802189/3","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"I have a root dir that has hundreds of folders in it that are named with a legacy company name and date format, I want to rename these files within all the folders with PowerShell, I have been trying all day but no luck thus far
I’m a noob to scripting, only ever normal have to do login scripts and easy stuff.<\/p>\n
I need to maintain the date format on the files so they need to look like example new_businessname06092021.csv<\/p>\n
Get-ChildItem –Path \"C:\\temp\\AMLReports\" -Recurse -Filter *.csv\nforeach($file in Get-ChildItem $SomeFolder)\n{\n $newname = ([String]$File).Replace(\"oldbuisnessname\",\"newbusinessname\")\n Rename-item -Path \"C:\\temp\\AMLReports\\Renamed\" $File $newname\n}\n\n<\/code><\/pre>\nHelp appreciated
<\/p>","upvoteCount":3,"datePublished":"2021-06-09T02:38:07.000Z","url":"https://community.spiceworks.com/t/powershell-file-rename-recuse-help-needed/802189/1","author":{"@type":"Person","name":"milesit","url":"https://community.spiceworks.com/u/milesit"}},{"@type":"Answer","text":"
Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n