[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
附件都传错了,搞什么搞

如果是ansi 编码,把 -1 改成 0
  1. Set fso = Createobject("Scripting.FileSystemObject")
  2. txt = fso.OpenTextFile("HIVECLS.INF", 1, false, -1).ReadAll
  3. Set re = New RegExp
  4. re.Pattern = "(\[Strings])([\s\S]+?)\1"
  5. re.IgnoreCase = true
  6. txt = re.Replace(txt, "$1$2")
  7. fso.OpenTextFile("New.inf", 2, true, -1).Write txt
复制代码
1

评分人数

TOP

回复 7# yuanyannian


    附件不是 unicode 编码格式

TOP

回复 8# yuanyannian


    如果还有其它问题,请更新顶楼内容,或重新发帖

TOP

  1. Set fso = Createobject("Scripting.FileSystemObject")
  2. For Each file in fso.GetFolder(".").Files
  3.         If LCase(Right(file, 4)) = ".inf" Then
  4.                 RegEx file, GetInfFormat(file)
  5.         End If
  6. Next
  7. MsgBox "OK"
  8. Function GetInfFormat(ByVal file)
  9.         With CreateObject("ADODB.Stream")
  10.                 .Mode = 3
  11.                 .Type = 1
  12.                 .Open
  13.                 .LoadFromFile file
  14.                 bin = .Read(2)
  15.         End With
  16.         s = Hex(AscB(MidB(bin, 1, 1))) & Hex(AscB(MidB(bin, 2)))
  17.         If UCase(s) = "FEFF" or UCase(s) = "FFFE" Then
  18.                 GetInfFormat = -1
  19.         Else GetInfFormat = 0
  20.         End If
  21. End Function
  22. Sub RegEx(ByVal file, intFormat)
  23.         Set f = fso.OpenTextFile(file, 1, false, intFormat)
  24.         txt = f.ReadAll : f.Close
  25.         Set re = New RegExp
  26.         re.Pattern = "(\[Strings])([\s\S]+?)\1"
  27.         re.IgnoreCase = true
  28.         If Not re.Test(txt) Then Exit Sub
  29.         Set f = fso.OpenTextFile("New_" & file.Name, 2, true, -1)
  30.         f.Write re.Replace(txt, "$1$2") : f.Close
  31. End Sub
复制代码
1

评分人数

    • yuanyannian: 感谢 apang 老师的无私支援。技术 + 1

TOP

返回列表