Section 7.6. Renaming Multiple Files at Once


7.6. Renaming Multiple Files at Once

To change the extensions of a folder of .htm files to .html files:

     MSH D:\MshScripts> get-childitem *.htm | foreach-object { rename-item $_.name $_.name.replace(".htm",".html") }

Instead of changing the extension, we can change part of the stem. For a folder containing image1.gif, image2.gif, etc., let's replace the "image" part with something more meaningful:

     MSH D:\MshScripts> get-childitem image*.gif | foreach-object     { rename-item $_.name $_.name.replace("image", "inventory") }

Alternatively, we can change all filenames to be lowercase:

     MSH D:\MshScripts> get-childitem | foreach-object     { rename-item $_.name $_.name.tolower( ) }




Monad Jumpstart
Monad Jumpstart
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 117

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net