Extract file . ZIP with accent on name

Asked

Viewed 901 times

6

I’m using the lib System.IO.Compression.ZipFile to unzip files .zip and came across a big problem while trying to extract files that have accents in the name.

If I try to extract with encoding UTF-8:

ZipFile.ExtractToDirectory(caminhoArquivoZip, "E:\\localParaExtrair", Encoding.UTF8);

Files that have accented names get the character instead of the accented letter.

If I pass another Encoding (Unicode, for example), a Exception:

No support for specified input name encoding.

If you try with Encoding.Default another strange character is in place of the accented letter.

Is this a library problem? Is there any way to get these files out properly?

I am fully aware that one should not write file names with accents, but I am not the one who creates the files.

2 answers

6


With this Enconding works:

ZipFile.ExtractToDirectory(caminhoArquivoZip, "E:\\localParaExtrair", System.Text.Encoding.GetEncoding(850));

The GetEncoding initializes a new class instance Encoding corresponding to codepage specified.

(Source: documentation of . Net)

The code page 850 represents the coding ibm850 - Eastern European (DOS)

  • 3

    Caraca, very good. You can complement the answer by explaining why the parameter 850 in the .GetEncoding()?

  • 2

    Thanks for the @Jéfersonbueno complementation

  • with me did not work, and appeared error: System.Notsupportedexception: No data is available for encoding 850

  • with me did not work, and appeared error: System.Notsupportedexception: No data is available for encoding 850

0

The file name and/or folder name cannot contain any special characters, such as accentuation. Just like folders cannot have ?/%$ ......

Even if you try it directly in windows explorer it will give you the same error.

  • 3

    Folders may have accentuated characters. http://imgur.com/TH9Xf8m

  • Folders can yes, but zipping files into folders with accents, no.

  • 3

    This answer is incorrect. Accentuation can be used normally in folders and files within a . zip, no problems. The question does not at any time refer to characters "prohibited" by OS.

  • [Window Title] Compressed (zipped) Folders Error [Content] 'C: Users Henrique.brisola Downloads[Untitled]. split PROFARMA DISTRIBUIDORA DE PRODUTOS FARMACÊUTICOS S.A' cannot be Compressed because it includes characters that cannot be used in a Compressed Folder, such as Ê. You should Rename this file or directory. [OK]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.