Powershell recursive filename read and rename

1

i have downloaded from my ftp server a directory tree using wget and forcing ascii encoding so now i hve a lot of folders and files names something like "foo%C3%BC" (some of the files/folders already have correct names because they only had ascii characters).

I'm now trying toconvert them back to utf-8 using powershell, i tried writing the following line to accomplish this

Get-ChildItem C:\Users\Administrator\Desktop\folder -Recurse | select BaseName | Rename-Item -NewName {[System.Web.HttpUtility]::UrlDecode{BaseName}}

but this is not working and gives me the following error

Rename-Item : Cannot rename because item at '@{BaseName=filename}' does not exist.
At line:1 char:88
+ ... ect BaseName | Rename-Item -NewName {[System.Web.HttpUtility]::UrlDecode{BaseNam ...
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Rename-Item], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RenameItemCommand

over and over again (i suppose once for every file found).

The command works niecly up to the pipe after "select BaseName" so the problem is in the renaming part.

Does anyone have any idea how to make it work?

John Smith

Posted 2016-11-03T16:04:39.343

Reputation: 111

My guess is the error is thrown because you're trying to rename based only on the BaseName, which doesn't include the path. – Ƭᴇcʜιᴇ007 – 2016-11-03T17:15:41.680

@Ƭᴇcʜιᴇ007 i thought that with the -NewName parameter i didn't have to have the path of the file (i'm not even really sure how i can get it). Do you have any suggestions on how i could try to fix this? – John Smith – 2016-11-03T19:18:00.070

No answers