Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - rename files (lots of files for newbie)

Reply
 
Old 06-07-2007   #1 (permalink)
light_wt


 
 

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 SpecsSystem Spec
Old 06-07-2007   #2 (permalink)
Kiron


 
 

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 SpecsSystem Spec
Old 06-08-2007   #3 (permalink)
light_wt


 
 

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 SpecsSystem Spec
Old 06-08-2007   #4 (permalink)
Kiron


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46