Thursday, January 31, 2013

PowerShell: Removing First 3 Characters from Filenames of Parent and Subfolders


I found several examples of renaming files but this one is simple and easy to change.

gci -include *.txt -recurse|ren -newname {($_.name).substring(3)}

Note: no carriage return, this is a single command
Note: Doesn't like spaces in the filenames

Run this command from the parent folder and it'll rename all the file types in the folder and all subfolders.  The only limitation I found is special characters in the folder or filename.