Working with directory with special characters

1

I have the following script:

$ExistPath = Test-Path -PathType container  C:\Publicação\SQL-Release\Services 


if ($ExistPath)
 {
     Write-Host "Removendo diretorio!"
     Remove-Item -Path C:\Publicação\SQL-Release\Services -Recurse -Force
 }

 Write-Host "Criando diretorio!"
 New-Item -ItemType Directory -Force -Path C:\Publicação\SQL-Release\Services

 Copy-Item .\Services\MyServices\bin\Release C:\Publicação\SQL-Release\Services\Nalin -Recurse

But when I run it, it creates a directory with characters that are very different than expected. In case:

C:\Publicação

How to solve?

Thank you.

    
asked by anonymous 31.05.2017 / 13:43

1 answer

2

You need to change the encoding ( encoding ) of the script through the command chcp .

In summary terms, the command changes the * encoding * in which your script is interpreted by powershell. The default code page for the Portuguese language is 860, so using the following command before the rest of the script should solve the problem:

chcp 860

Note that calling the command without arguments causes Powershell to print the page of code that is currently in use.

Link to command documentation , if you are curious, or need to do more things related in the future.

Q.: The documentation does not mention, but there are code pages with much higher numbers. Undocumented pages can represent, for example, UNICODE. I believe, however, that page 860 is enough to solve the problem of the question.

    
31.05.2017 / 13:50