Search This Blog

Saturday, March 15, 2008

Two PowerShell oddities with "Rename-Item" and "Move-Item"

Oddity 1: I've got a subdirectory in a directory named "python." I want to rename it "Python," just change the case of the directory name.

Can't seem to do it with the PowerShell "Rename-Item" command. None of these will work:

rename-item python Python
rename-item 'python' 'Python'
rename-item 'C:\python' 'C:\Python'

Same when using double quotes instead of single quotes. All get an error message that the source and destination names are the same. The workaround to get me back working again was simple:

rename-item python tempname
rename-item tempname Python

By and large I like PowerShell's VB-style slackness with case sensitivity but a couple years of coding with C# now has given me a definite preference for tighter discipline. It's just too bad you can't turn case sensitivity on and off.

I Googled this problem and didn't find any other complaints or solutions, I'm guessing that this is just not that big a problem for Microsoft. Maybe it'll be quietly fixed in PowerShell 2.

Oddity 2:

The old DOS "Move" command and the PowerShell "Move-Item" commands are no longer equivalent, and in a good way. The difference is when moving items between volumes: when moving something on the same volume the two are equivalent, but when moving between volumes ... well, it won't let you do it. You've got to do a copy from one volume to another, then manually delete the original.

Overall PowerShell is so utterly superior to DOS that it's hard to conceive of a feature being "missing" from it where it was once present in DOS; rather, it's removed a bug from DOS.

No comments: