[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. Rem On Error Resume Next
  2. Dim reg1
  3. Set reg1 = New RegExp
  4. reg1.Pattern = "\b(PIN(?:ORDER|SWAP)[ \t]+)\S+"
  5. reg1.Global = True
  6. Dim reg2
  7. Set reg2 = New RegExp
  8. reg2.Pattern = "\b(FUNCTION[ \t]+)\S+([ \t]+)\S+"
  9. reg2.Global = True
  10. Dim fso, objFile, ext
  11. Set fso = CreateObject("Scripting.FileSystemObject")
  12. For Each objFile In fso.GetFolder(".").Files
  13.     ext = fso.GetExtensionName(objFile.Path)
  14.     If LCase(ext) = "txt" Then
  15.         replaceStr objFile.Path
  16.     End If
  17. Next
  18. Function replaceStr(filePath)
  19.     Dim f, s
  20.     Set f = fso.OpenTextFile(filePath)
  21.     s = f.ReadAll
  22.     s = reg1.Replace(s, "$1NAME")
  23.     s = reg2.Replace(s, "$1NAME$2RENAME")
  24.     f.Close
  25.     fso.OpenTextFile(filePath, 2, True).Write(s)
  26. End Function
  27. MsgBox "Done"
复制代码
1

评分人数

TOP

本帖最后由 WHY 于 2021-1-5 23:30 编辑

回复 3# loveforjg


    把 PINORDER 和 FUNCTION 之后的字符改名,把 PINSWAP 及之后的多行数据删除,多行数据判断的依据:以逗号+回车换行结束。
  1. Rem On Error Resume Next
  2. Dim reg1
  3. Set reg1 = New RegExp
  4. reg1.Pattern = "\b(PINORDER[ \t]+)\S+"
  5. reg1.Global = True
  6. Dim reg2
  7. Set reg2 = New RegExp
  8. reg2.Pattern = "\b(FUNCTION[ \t]+)\S+([ \t]+)\S+"
  9. reg2.Global = True
  10. Dim reg3
  11. Set reg3 = New RegExp
  12. reg3.Pattern = "\bPINSWAP[ \t](?:[^\r\n,]|,\r\n)+(?:\r\n)?"
  13. reg3.Global = True
  14. Dim fso, objFile, ext
  15. Set fso = CreateObject("Scripting.FileSystemObject")
  16. For Each objFile In fso.GetFolder(".").Files
  17.     ext = fso.GetExtensionName(objFile.Path)
  18.     If LCase(ext) = "txt" Then
  19.         replaceStr objFile.Path
  20.     End If
  21. Next
  22. Function replaceStr(filePath)
  23.     Dim f, s
  24.     Set f = fso.OpenTextFile(filePath)
  25.     s = f.ReadAll
  26.     s = reg1.Replace(s, "$1NAME")
  27.     s = reg2.Replace(s, "$1NAME$2RENAME")
  28.     s = reg3.Replace(s, "")
  29.     f.Close
  30.     fso.OpenTextFile(filePath, 2, True).Write(s)
  31. End Function
  32. MsgBox "Done"
复制代码
1

评分人数

TOP

返回列表