/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" PowerShell make a drive of an UNC path "," Some Powershell News "," PowerShell Import and Export a DirectoryTree and S... "," PowerShell How Can I Query a Text File and Retriev... "," PowerShell Import Shares and Security info From CSV "," An other PowerShell Blog is born "," Windows PowerShell: TFM "," PowerShell Export Shares and Security info to CSV "," powershell (Monad) Home on computerperformance.co.uk "," PowerShell in Action "," ")

Thursday, May 11, 2006

 


PowerShell : How Can I Rename Files Using File Names I've Written to a Text File?



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 Commands

is 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 :


Comments:
Blogger /\/\o\/\/
Andrew,

thanks for the comment.

I fixed them,

that [censored] blogger interface does eat my pipelines,

greetings /\/\o\/\/
 
Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?