Search This Blog

2013-02-28

PowerShell: Rename directory with square bracket

Product: PowerShell

I have a corrupted partition, and after recovered with GetDataBack, all the directories becomes a hexcode enclosed with square bracket.

So I used following command to remove the square bracket, which is used as a wild-card in PowerShell. Surprisingly this trick is hard to find in Internet


ls -filter *`[*`]* | move-item -dest {$_ -replace '\[|\]',''}

Explanation:
1. ls command filter directory or file name containing square bracket
2. Inside move-item -dest, I used escape character \ followed by left and right square bracket
3. I used or operator | to replace both square bracket characters

No comments: