[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
powershell不熟悉,vbs来一个
  1. Const b_txt    = "b.txt"
  2. Const out_text = "all.tmp"
  3. Const FailName = "bug.txt"
  4. Set oFSO = CreateObject("Scripting.FileSystemObject")
  5. Set oTextStream1 = oFSO.OpenTextFile(out_text, 2, True)
  6. Set oTextStream2 = oFSO.OpenTextFile(FailName, 2, True)
  7. Set oStream = CreateObject("ADODB.Stream")
  8. oStream.Type = 2    'adTypeText
  9. oStream.Mode = 3    'adModeReadWrite
  10. oStream.Charset = "GBK"
  11. oStream.Open()
  12. oStream.LoadFromFile b_txt
  13. arr = Split(oStream.ReadText(), vbCrLf)
  14. oStream.Close()
  15. For Each i In arr
  16.     If oFSO.FileExists(i) Then
  17.         oStream.Charset = checkCharset(i)
  18.         oStream.Open()
  19.         oStream.LoadFromFile i
  20.         s = oStream.ReadText()
  21.         oStream.Close()
  22.         s = RePlace(s, vbCrLf, vbCr)
  23.         s = RePlace(s, vbLf, vbCr)
  24.         s = RePlace(s, vbCr, vbCrLf)
  25.         oTextStream1.WriteLine s & vbCrLf
  26.     Else
  27.         oTextStream2.WriteLine i
  28.     End If
  29. Next
  30. MsgBox "ok"
  31. Function checkCharset(ByVal file)
  32.     Dim oStream, oRegExp, arr(), s
  33.     Set oStream = CreateObject("ADODB.Stream")
  34.     oStream.Type = 1    'adTypeBinary
  35.     oStream.Mode = 3    'adModeReadWrite
  36.     oStream.Open()
  37.     oStream.LoadFromFile file
  38.     If oStream.Size >= 2 Then
  39.         s = Hex(AscB(oStream.Read(1)))
  40.         s = s & Hex(AscB(oStream.Read(1)))
  41.         If s = "FFFE" Or s = "FEFF" Then
  42.             checkCharset = "Unicode"
  43.             Exit Function
  44.         End If
  45.     End If
  46.     oStream.Position = 0
  47.     ReDim arr(oStream.Size - 1)
  48.     For s = 0 To oStream.Size - 1
  49.         arr(s) = ChrW(AscB(oStream.Read(1)))
  50.     Next
  51.     oStream.Close()
  52.     s = "[\xC0-\xDF]([^\x80-\xBF]|$)"        & _
  53.         "|[\xE0-\xEF].{0,1}([^\x80-\xBF]|$)" & _
  54.         "|[\xF0-\xF7].{0,2}([^\x80-\xBF]|$)" & _
  55.         "|[\xF8-\xFB].{0,3}([^\x80-\xBF]|$)" & _
  56.         "|[\xFC-\xFD].{0,4}([^\x80-\xBF]|$)" & _
  57.         "|[\xFE-\xFE].{0,5}([^\x80-\xBF]|$)" & _
  58.         "|[\x00-\x7F][\x80-\xBF]"            & _
  59.         "|[\xC0-\xDF].[\x80-\xBF]"           & _
  60.         "|[\xE0-\xEF]..[\x80-\xBF]"          & _
  61.         "|[\xF0-\xF7]...[\x80-\xBF]"         & _
  62.         "|[\xF8-\xFB]....[\x80-\xBF]"        & _
  63.         "|[\xFC-\xFD].....[\x80-\xBF]"       & _
  64.         "|[\xFE-\xFE]......[\x80-\xBF]"      & _
  65.         "|^[\x80-\xBF]"
  66.     Set oRegExp = New RegExp
  67.     oRegExp.MultiLine = False
  68.     oRegExp.Pattern = s
  69.     checkCharset = "GBK"
  70.     If Not oRegExp.Test(Join(arr, "")) Then checkCharset = "UTF-8"
  71. End Function
复制代码

QQ 20147578

TOP

回复 4# 娜美


    运行结果反馈下,看看有没有问题

QQ 20147578

TOP

你说的大文件是多大,100M还是1G还是2G

QQ 20147578

TOP

返回列表