![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | rename files (lots of files for newbie) I have a list of files which has 3 parts name, liked the following: a.system.ini a.appl.ini a.ado.ini b.web.ini c.custom.ini .. .. .. The leading a.* b.* c.* portion are needed to be removed. I've played with this two. First one only append something to the name. 2nd doesn't work. I've got >> after finishing the command. dir |Rename-Item -NewName {$_.Name + "1"} get-childitem *.ini | foreach { move-item -literalpath $_ $_.name.replace("[a.]","" ) How can I use the rename-Item or move-item to rename or remove the leading portions? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: rename files (lots of files for newbie) You can rename the files using the -replace operator in a subexpression and passing this value as the -newName parameter of the Rename-Item Cmdlet like this: Get-ChildItem -filter *.ini | Foreach {Rename $_ -new $($_.name -replace '^[a-z]\.')} ....but this will return an error if the new name already exists, e.g.: a.appl.ini b.appl.ini ...."a.appl.ini" will be renamed "appl.ini" but "b.appl.ini" can not be renamed "appl.ini" -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: rename files (lots of files for newbie) thank you, Kiron. the note on error is very kind of you. I had luck with Rename-Item. -- Jon. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: rename files (lots of files for newbie) You're welcome. Sorry about the typo in the Foreach statement block, Rename-Item instead of just Rename. Get-ChildItem -filter *.ini | Foreach {Rename-Item $_ -new $($_.name -replace '^[a-z]\.')} -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Lots of system files missing | System Security | |||
| I think system restore deleted lots of my cs files on Vista Ultimate | Vista file management | |||
| rename all files from a directory to a list of files ... | PowerShell | |||
| cant delete files or rename files | Vista security | |||
| newbie has lots of questions - Please answer whichever you like | Vista General | |||