0

I have written ps script to download zip from server and unzip it at local, script is working fine as long as zipped files don't contain any special character.
But when some of files from server having character like "àòèéù" after unzipping some how it's showing ?or [] not original data.
If i extract same zip using winrar or other tool i can see orignal character set as it is and it's expected.
Please help me to understand or resolve this issue how i can persist orignal character while unzipping using power shell script.

$client = New-Object "System.Net.WebClient"
#$client.Headers.add("Authorization",$CookieContainer.GetCookieHeader($token))
$client.Headers.add("Authorization",$token)

#$client.UseDefaultCredentials = $true
#$client.Credentials = Get-Credential
try
{
"Downloading"
 $client.DownloadFile([string]$url,[string]$documents_path)

"Finished Download"

"Unzipping Zip"
"$documents_path"

$zipPackage = (new-object -com shell.application).NameSpace($documents_path)
$destinationFolder = (new-object -com shell.application).NameSpace($target_path)
$destinationFolder.CopyHere($zipPackage.Items(),16)
"$target_path"
"Unzipping Zip Done"

}

Update:
It's only happening for xml files without encoding information, how i can encode this xml file while extracting or after extracting.

Gan
  • 624
  • 1
  • 10
  • 31

1 Answers1

0

The software that you are using to read the file may be trying to read it in a different encoding format than it was saved in. For instance, Excel will often open a file for windows users in an ANSI format like WIN-1252 even if you wrote it in UTF-8. You can use a utility like iconv (depending on what platform you are on) to convert files from one format to another.

inquiring minds
  • 1,785
  • 2
  • 15
  • 16
  • Agreed. I've used the COM Shell APIs to unzip files without problem. Unzip shouldn't care about characters or encodings, just the bytes in the zip file. I think the problem is in the program you're using to view the files once they're unzipped. – Aaron Jensen Sep 05 '14 at 21:02
  • @inquiring minds it's only happening in case of xml, so can you tell me how i can identify xml and enforce encoding while extracting – Gan Sep 07 '14 at 11:47
  • I don't have a windows machine, but I did see this post that might help you: http://stackoverflow.com/questions/7585548/powershellscript-bad-file-encoding-conversation – inquiring minds Sep 08 '14 at 13:26