I have found code on here which does what I need it to it
$files = gci -filter "*.txt" |select fullname
foreach ($file in $files) {
$filename = $file.fullname
$newFilename = $filename.Replace(".", " ")
rename-item $filename $newFilename
}
I require the code to change the file name and keep the file extension. The code above replaces "." with " ". I can code it to rename the file again to add the extension back. Just wanted to see if there was a better way to do it.
Cheers
Change 'old'
& 'new'
to whatever you want
Remove the -Whatif
to apply the command.
Get-ChildItem -Path C:\temp\files -Filter *.txt |
Rename-Item -NewName {$_.Basename.Replace("old","new") + $_.extension} -WhatIf -Verbose
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With