Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

rename files (lots of files for newbie)

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-07-2007   #1 (permalink)
light_wt
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 SpecsSystem Spec
Old 06-07-2007   #2 (permalink)
Kiron
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 SpecsSystem Spec
Old 06-08-2007   #3 (permalink)
light_wt
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 SpecsSystem Spec
Old 06-08-2007   #4 (permalink)
Kiron
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 SpecsSystem Spec
Closed Thread

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


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com 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 2005-2008