(view source code of gettxttype.vbs as plain text)
Option Explicit
Dim objFile, objFSO
Dim strEnc, strFile, strTest
Const ForReading = 1
Const TristateFalse = 0
With WScript.Arguments
If .Named.Count > 0 Then
Syntax
End If
If .Unnamed.Count = 1 Then
strFile = WScript.Arguments(0)
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
If objFSO.FileExists( strFile ) Then
Set objFile = objFSO.OpenTextFile( strFile, ForReading, TristateFalse )
Else
Set objFSO = Nothing
Syntax
End If
Else
Syntax
End If
End With
strEnc = "ANSI"
strTest = objFile.Read( 4 )
If strTest = Chr( 0 ) & Chr( 0 ) & Chr( 254 ) & Chr( 255 ) Then strEnc = "Unicode-32 (BE)"
If strTest = Chr( 0 ) & Chr( 0 ) & Chr( 255 ) & Chr( 254 ) Then strEnc = "Unicode-32 (LE)"
If strTest = Chr( 43 ) & Chr( 47 ) & Chr( 118 ) & Chr( 43 ) Then strEnc = "UTF-7"
If strTest = Chr( 43 ) & Chr( 47 ) & Chr( 118 ) & Chr( 47 ) Then strEnc = "UTF-7"
If strTest = Chr( 43 ) & Chr( 47 ) & Chr( 118 ) & Chr( 56 ) Then strEnc = "UTF-7"
If strTest = Chr( 43 ) & Chr( 47 ) & Chr( 118 ) & Chr( 57 ) Then strEnc = "UTF-7"
If strTest = Chr( 221 ) & Chr( 115 ) & Chr( 102 ) & Chr( 115 ) Then strEnc = "UTF-EBCDIC"
If strTest = Chr( 132 ) & Chr( 49 ) & Chr( 149 ) & Chr( 51 ) Then strEnc = "GB-18030"
strTest = Left( strTest, 3 )
If strTest = Chr( 239 ) & Chr( 187 ) & Chr( 191 ) Then strEnc = "UTF-8"
If strTest = Chr( 247 ) & Chr( 100 ) & Chr( 76 ) Then strEnc = "UTF-1"
If strTest = Chr( 14 ) & Chr( 254 ) & Chr( 255 ) Then strEnc = "SCSU"
If strTest = Chr( 251 ) & Chr( 238 ) & Chr( 40 ) Then strEnc = "BOCU-1"
strTest = Left( strTest, 2 )
If strTest = Chr( 254 ) & Chr( 255 ) Then strEnc = "Unicode-16 (BE)"
If strTest = Chr( 255 ) & Chr( 254 ) Then strEnc = "Unicode-16 (LE)"
WScript.Echo strEnc
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
Sub Syntax( )
Dim strMsg
strMsg = vbCrLf _
& "GetTxtType.vbs, Version 1.00" & vbCrLf _
& "Find a text file's text encoding by reading its BOM (Byte Order Mark)" _
& vbCrLf & vbCrLf _
& "Usage: GETTXTTYPE.VBS input_file" _
& vbCrLf & vbCrLf _
& "Note: If no BOM is found, the script assumes ANSI." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com" & vbCrLf
WScript.Echo strMsg
WScript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0061 seconds