Renaming folders and files [SOLVED]

by at 2012-12-02 19:55:21

[Tested using PowerShell v2 and v3]

If you receive the following error or are having issues renaming parent folders, subfolders, and files, this one-liner may help. I had to change a large number of folders and files from upper-case to lower-case. I made a slight modification to the one-liner listed here:

Error: Rename-Item: Source and destination path must be different.

Get-ChildItem -include * -recurse | foreach {
$oldname=$.name; Rename-Item $ -NewName (“pre”+$oldname) -PassThru |
rename-item -newname ($oldname[0].tostring().tolower()+$oldname.substring(1).tolower()) -PassThru

## This will change subfolders and files, but not parent folders from upper-case to lower-case.
Get-ChildItem -include * -recurse | Rename-Item -NewName {$} -PassThru