![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lots of system files missing | shrinkers | System Security | 2 | 05-15-2008 08:49 PM |
| I think system restore deleted lots of my cs files on Vista Ultimate | Dave | Vista file management | 10 | 10-29-2007 02:01 PM |
| rename all files from a directory to a list of files ... | show3r@gmail.com | PowerShell | 4 | 08-25-2007 10:43 PM |
| cant delete files or rename files | nurselisa | Vista security | 2 | 05-03-2007 01:40 PM |
| newbie has lots of questions - Please answer whichever you like | species8350 | Vista General | 3 | 04-14-2007 05:41 PM |