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?

  • 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 Nov 3 '16 at 17:15
  • @Ƭᴇ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 Nov 3 '16 at 19:18

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.