This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
and an other Hey Scripting Guy Item translation to PowerShell,
How Can I Rename Files Using File Names I've Written to a Text File?import-csv names.csv %| {ren $_.old $_.new}as this line (as remarked by Scott Hansellman), see
Upgrading MSH, My first Windows PowerShell Commandsis a bit awkward opposed to ren *.msh *.ps1 in the CMD shell.
ls . *.msh -rec | rename-item -newname {$_.name -replace ".msh",".ps1"} -WhatIf
you can see, by this example, if you compare it to the VBscript version is not that bad ;-)
Here the commandline code of the sample I made for this :
# make testdir
MowPS>md ren
Directory: Microsoft.PowerShell.Core\FileSystem::C:
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2006-05-11 5:06 PM ren
# create test files
MowPS>cd ren
MowPS>ls
MowPS>sc 001.jpg 'bla'
MowPS>sc 002.jpg 'bla'
# make List
MowPS>copycon
Old,New
001.jpg,foo.jpg
002.jpg,bar.jpg
^Z
cmdlet out-file at command pipeline position 1
Supply values for the following parameters:
FilePath: Names.csv
# CopyCon is a custom Function I like
MowPS>gc function:copycon
if ($args[0] -eq $null) {[system.console]::in.readtoend() out-file}
Else {[system.console]::in.readtoend() out-file $args[0]}
# the "script" itself
MowPS>import-csv names.csv %| {ren $_.old $_.new}
# Checking
MowPS>ls
Directory: Microsoft.PowerShell.Core\FileSystem::C:\ren
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2006-05-11 5:07 PM 5 bar.jpg
-a--- 2006-05-11 5:06 PM 5 foo.jpg
-a--- 2006-05-11 5:10 PM 88 Names.csv
Enjoy,
Greetings /\/\o\/\/
Tags : Monad msh PowerShell