Home » Main » Manning Forums » 2006 » Windows PowerShell in Action

Thread: Problem with square bracket and rename-item

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Pages: 1 - Last Post: Sep 21, 2007 1:25 AM by: brucepay
franck

Posts: 12
From: Switzerland
Registered: 9/19/07
Problem with square bracket and rename-item
Posted: Sep 20, 2007 7:19 AM
  Click to reply to this thread Reply

Hi all

I have with 'rename-item' exactly the same problem as with 'get-acl' (see my message from Sep 19, 2007 8:03 AM 'Problem with square brackets and get-acl (no -literalpath)'

the square bracket in pathname can't be escape.

i can't rename a file with '[' or ']' in pathname

- gci 'test''[1]file.txt' - is working but - rename-item 'test''[1]file.txt' newname.txt not

I get 'rename-item: Cannot rename because item at 'test[1]file.txt' does not exist.

It 'rename-item' also buggy !!??

Greeting Franck

brucepay

Posts: 142
From: Redmond, WA
Registered: 9/8/05
Re: Problem with square bracket and rename-item
Posted: Sep 21, 2007 1:25 AM   in response to: franck in response to: franck
  Click to reply to this thread Reply

Yup - it's buggy but there is a good workaround for this one.

Here's what happened. There was a push just before the release of version 1 where we went through and cleaned up most of the wildcard quoting bugs. This was done right at the end so the work was triaged pretty heavily. Only the most important things got fixed since we were locking done for RTM/RTW. We fixed all of the *-Item commands except for Rename-Item, the rational being that the Rename-Item cmdlet isn't necessary since you can use Move-Item instead and Move-Item does support the -LiteralPath parameter. Here's an example:

PS (48) > new-item [1].txt # create a file with [ ] in the name
Type: file


Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp\junk


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/20/2007 11:11 PM 0 [1].txt


PS (49) > move-item -literal [1].txt one[1].txt # now rename/move it...
PS (50) > ls *`]*.txt


Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp\junk


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/20/2007 11:11 PM 0 one[1].txt

As Jeffrey Snover is so fond of saying, to ship is to choose. Some things get fixed, some don't. The Acl thing should have been fixed because there is no good workaround. The Rename-Item bug is less of an issue except, of course, when users encounter the problem and get annoyed with us. This should, at least, be rel-noted...

-bruce

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff