Charset conversion of very large files - 2GB and more | 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 |
| Charset conversion of very large files - 2GB and more | |
|---|---|
Option Explicit FileConvert "H:\giga.dat", "utf-8", "Z:\giga-01.dat", "windows-1250" 'FileConvert "H:\giga.dat", "windows-1250", "Z:\giga-01.dat", "windows-1250" 'Charset conversion of a large file - 2GB, 4GB or more 'ScriptUtilities.ByteArray VBA sample Sub FileConvert(SourceFileName, SourceCharSet, DestFileName, DestinationCharSet) 'Set block size. Bigger block: better speed, more resources. Const BlockSize = &H100000 Dim sPos, dPos, sByteArray, dByteArray, TotalBytes , ReadBlockSize Set sByteArray = CreateObject("ScriptUtils.ByteArray") sByteArray.CharSet = SourceCharSet 'Get a source file length. TotalBytes = GetFileSize(SourceFileName) 'Clear the destination file DeleteFile DestFileName ' If TotalBytes > 0 Then 'Convert only nonzero files. 'For each data block from the source file For sPos = 0 To TotalBytes Step BlockSize Wscript.Echo sPos If BlockSize + sPos > TotalBytes Then 'Last block - read only rest of data. ReadBlockSize = TotalBytes - sPos Else ReadBlockSize = BlockSize End If 'Read the block of source data. sByteArray.ReadFrom SourceFileName, sPos + 1, ReadBlockSize 'Convert the data to the destination charset Set dByteArray = sByteArray.CharSetConvert(DestinationCharSet) ' and store them to a disk. 0 means store the data at the end of file dByteArray.SaveAs DestFileName, 0 'Increment the destination position dPos = dPos + dByteArray.Length Next ' sPos ' End If ' TotalBytes > 0 Then End Sub 'Get file size - 64 bit version, unlimited size Function GetFileSize(FileName) Dim Kernel: Set Kernel = CreateObject("ScriptUtils.Kernel") On Error Resume Next GetFileSize = Kernel.GetFileSize(FileName) If err<>0 Then GetFileSize = 0 On Error Goto 0 End Function Function DeleteFile(FileName) Dim Kernel Set Kernel = CreateObject("ScriptUtils.Kernel") On Error Resume Next Kernel.DeleteFile FileName On Error Goto 0 End Function | |