Comment connaitre encodage des fichiers ANSI ou UTF8
Bonjour,
Je dois parser un répertoire avec des fichiers txt, asp, js, jpg, pdf et des sous répertoires.
Et je dois vérifier que mes fichiers sont bien encodé en ANSI.
J ai bien trouvé sur le net comment reconnaitre les fichiers UTF8 avec BOM
avec le bout de code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| Dim bom = New Byte(3) {}
Using file = New FileStream(filename, FileMode.Open, FileAccess.Read)
file.Read(bom, 0, 4)
End Using
If bom(0) = &H2B AndAlso bom(1) = &H2F AndAlso bom(2) = &H76 Then Return Encoding.UTF7
If bom(0) = &HEF AndAlso bom(1) = &HBB AndAlso bom(2) = &HBF Then Return Encoding.UTF8
If bom(0) = &HFF AndAlso bom(1) = &HFE AndAlso bom(2) = 0 AndAlso bom(3) = 0 Then Return Encoding.UTF32
If bom(0) = &HFF AndAlso bom(1) = &HFE Then Return Encoding.Unicode
If bom(0) = &HFE AndAlso bom(1) = &HFF Then Return Encoding.BigEndianUnicode
If bom(0) = 0 AndAlso bom(1) = 0 AndAlso bom(2) = &HFE AndAlso bom(3) = &HFF Then Return New UTF32Encoding(True, True) |
Par contre j'ai pas trouvé comment différencier les fichiers encodés en ANSI et UTF8.
Je vous remercie d'avance de votre aide.
Joel