Batch charset conversion - convert all .txt files in a folder from ibm-850 unicode utf-8 | ActiveX/VBSScript registry editor
ActiveX NT User account manager
Export MDB/DBF from ASP
Url replacer, IIS url rewrite Active LogFile Email export ActiveX/ASP Scripting Dictionary object
| ||
| Sample for ScriptUtils.ByteArray.CharSetConvert |
| Batch charset conversion - convert all .txt files in a folder from ibm-850 unicode utf-8 | |
|---|---|
Option Explicit
'Batch Convert of ibm-850 files to unicode utf-8 with BOM header
Dim FS, Folder, File, SourceFile, DestFile
Set FS = CreateObject("Scripting.FileSystemObject")
Set Folder = FS.GetFolder(".")
'Process each file in folder
For Each File In Folder.Files
'For each .txt file
If LCase(Right(File.Name,4)) = ".txt" Then
'get a source file name
SourceFile = File.Path
'get a destination file name
DestFile = Replace(File.Path, ".txt", "-utf.txt")
'convert the file
FileConvert File.Path, "ibm850", DestFile, "utf-8"
End If
Next
Sub FileConvert(SourceFile, SourceCharSet, DestinationFile, DestinationCharSet)
'Save BOM header at the start of destination file
SaveBOMHeader DestinationFile, "EFBBBF"
Dim ByteArray
Set ByteArray = CreateObject("ScriptUtils.ByteArray")
'Read the source data from a file
ByteArray.ReadFrom SourceFile
'Set character set of the source file
ByteArray.CharSet = SourceCharSet
'Convert the data to a destination charset and save them
ByteArray.CharSetConvert(DestinationCharSet).SaveAs DestinationFile, 4
End Sub
Sub SaveBOMHeader(FileName, Header)
'create byte array object
Dim ByteArray
Set ByteArray = CreateObject("ScriptUtils.ByteArray")
'the bytearray contains BOM header - 3 bytes.
ByteArray.HexString = Header
'Save the BOM header to the FileName
ByteArray.SaveAs FileName
End Sub | |