convert all .txt files in a folder from ibm-850 unicode utf-8

文章推薦指數: 80 %
投票人數:10人

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 ... Batchcharsetconversion-convertall.txtfilesinafolderfromibm-850unicodeutf-8 SampleforScriptUtils.ByteArray.CharSetConvert|Changes|Purchase|Download Examples     Thissamplecontainsshortalgorithmtoconvertmorefiles(allfilesinonefolder)fromonecharactersettoanother.Thesampleworksforanycodepage(unicodeutf-8->shift-jis,windows-1250->utf-8,..)andshorterfiles,thefilesareconvertedinmemoryandthereisnogoodideatouseitforfilesover100MB.(SeeCharsetconversionofverylargefiles-2GBandmore).Batchcharsetconversion-convertall.txtfilesinafolderfromibm-850unicodeutf-8 OptionExplicit 'BatchConvertofibm-850filestounicodeutf-8withBOMheader DimFS,Folder,File,SourceFile,DestFile SetFS=CreateObject("Scripting.FileSystemObject") SetFolder=FS.GetFolder(".") 'Processeachfileinfolder ForEachFileInFolder.Files 'Foreach.txtfile IfLCase(Right(File.Name,4))=".txt"Then 'getasourcefilename SourceFile=File.Path 'getadestinationfilename DestFile=Replace(File.Path,".txt","-utf.txt") 'convertthefile FileConvertFile.Path,"ibm850",DestFile,"utf-8" EndIf Next SubFileConvert(SourceFile,SourceCharSet,DestinationFile,DestinationCharSet) 'SaveBOMheaderatthestartofdestinationfile SaveBOMHeaderDestinationFile,"EFBBBF" DimByteArray SetByteArray=CreateObject("ScriptUtils.ByteArray") 'Readthesourcedatafromafile ByteArray.ReadFromSourceFile 'Setcharactersetofthesourcefile ByteArray.CharSet=SourceCharSet 'Convertthedatatoadestinationcharsetandsavethem ByteArray.CharSetConvert(DestinationCharSet).SaveAsDestinationFile,4 EndSub SubSaveBOMHeader(FileName,Header) 'createbytearrayobject DimByteArray SetByteArray=CreateObject("ScriptUtils.ByteArray") 'thebytearraycontainsBOMheader-3bytes. ByteArray.HexString=Header 'SavetheBOMheadertotheFileName ByteArray.SaveAsFileName EndSub OtherlinksfortheBatchcharsetconversion-convertall.txtfilesinafolderfromibm-850unicodeutf-8sample ScriptUtils.ByteArray Workswithsafearraybinarydata-save/restorebinarydatafrom/toadisk,converttoastring/hexstring,codepage/charsetconversions,Base64conversion,etc.    ByteArrayisaCOMclassspeciallydesignedtoworkwithMicrosoftWindowsScriptingengines-VBScriptandJScriptinActiveServerPagesorWSHandinCHMorHTAapplications.ItalsoworkswithVBNet,Visualbasic(VBA-VB5,VB6,Word,Excel,Access,…),C#,J#,C++,ASP,ASP.Net,DelphiandwithT-SQLOLEfunctions-seeUseByteArrayobjectarticle.YoucanalsousetheobjectinotherprogrammingenvironmentswithCOMsupport,suchisPowerBuilder.     SourcecodeforByteArrayisavailablewithindistributionlicense,pleaseseeLicensepageforASPfileuploadandScriptUtilities. ScriptUtils HugeASPuploadiseasytouse,hi-performanceASPfileuploadcomponentwithprogressbarindicator.Thiscomponentletsyouuploadmultiplefileswithsizeupto4GBtoadiskoradatabasealongwithanotherformfields.HugeASPfileuploadisamostfeatureduploadcomponentonamarketwithcompetitivepriceandagreatperformance.Thesoftwarehasalsoafreeversionofaspuploadwithprogress,calledPureaspupload,writteninplainVBS,withoutcomponents(soyoudonotneedtoinstallanythingonserver).ThisinstallationpackagecontainsalsoScriptUtilitieslibrary.ScriptUtilitiesletsyoucreatehi-performancelogfiles,workswithbinarydata,youcandownloadmultiplefileswithzip/arjcompression,workwithINIfilesandmuchmorewiththeASPutility. ©1996-2011AntoninFoller,MotobitSoftware|About,Contacts|e-mail:[email protected] OtherMotobitlinks:  IISTracer,real-timeIISmonitor  ASPfileupload-uploadfilestoASP.  ActiveX/VBSScriptregistryeditor  ActiveXNTUseraccountmanager  ExportMDB/DBFfromASP ActiveLogFile  Emailexport  ActiveX/ASPScriptingDictionaryobject



請為這篇文章評分?