[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 a20150604 于 2019-12-17 15:36 编辑

回复 1# chong08
  1. Rem^ & @echo off & mode 300,9999
  2. Rem^ &cscript //NoLogo //E:VBScript "%~f0"
  3. Rem^ &pause
  4. Rem^ &goto :eof
  5. Public yyyyMMdd
  6. Call main
  7. Sub main()
  8.     dttm = Now
  9.     yyyyMMdd = Year(dttm) & "" & Right("0" & Month(dttm), 2) & "" & Right("0" & Day(dttm), 2)
  10.     Set fso = CreateObject("Scripting.FileSystemObject")
  11.     ' 脚本对象 和 当前目录
  12.     Set obj_wsc_shell = CreateObject("wscript.shell")
  13.     HostFolder = obj_wsc_shell.CurrentDirectory & "\"
  14.     ' HostFolder = ThisWorkbook.Path & "\"
  15.     Call DoFolder(fso.GetFolder(HostFolder))
  16.     wscript.Quit
  17. End Sub
  18. Sub DoFolder(Folder)
  19.     ' 在子目录中递归调用
  20.     Dim SubFolder
  21.     For Each SubFolder In Folder.SubFolders
  22.         Call DoFolder(SubFolder)
  23.     Next
  24.     Dim file
  25.     For Each file In Folder.Files
  26.         Call doFile(file)
  27.     Next
  28. End Sub
  29. Sub doFile(ByRef input_file)
  30.     ' 分解获取 文件名 和 扩展名
  31.     If InStr(input_file.Name, ".") > 0 Then
  32.         arr = Split(input_file.Name, ".")
  33.         ext_name = UCase(arr(UBound(arr)))
  34.         dot_ext_name = "." & ext_name
  35.     Else
  36.         ext_name = ""
  37.         dot_ext_name = ""
  38.     End If
  39.     ' 跳过 非 TIF 文件
  40.     If Not ("TIF" = ext_name) Then
  41.         Exit Sub
  42.     End If
  43.    
  44.     file_name = Left(input_file.Name, Len(input_file.Name) - Len(dot_ext_name))
  45.    
  46.     Dim regEx
  47.     Set regEx = New RegExp
  48.     regEx.Pattern = "\d+_\d+_([^\-\s]+)-[^\d]*(\d+)[\s\S]*(Yellow|Black|Cyan|Magenta)"
  49.     regEx.IgnoreCase = True
  50.     Rem regEx.Global = True
  51.     wscript.echo "file_name:" & file_name
  52.     Set oMatches = regEx.Execute(file_name)
  53.     If oMatches.Count > 0 Then
  54.         Set oMatch = oMatches(0)
  55.         wscript.echo "file_name:" & file_name & " 0:" & oMatch.SubMatches(0) & " 1:" & oMatch.SubMatches(1) & " 2:" & oMatch.SubMatches(2)
  56.         new_name = ""
  57.         Select Case oMatch.SubMatches(0)
  58.             Case "光明日报"
  59.                 new_name = new_name & "gmrb" & "-"
  60.             Case "第一财经"
  61.                 new_name = new_name & "dycj" & "-"
  62.         End Select
  63.         new_name = new_name & Right("00" & oMatch.SubMatches(1), 3) & "-" & yyyyMMdd
  64.         Select Case UCase(oMatch.SubMatches(2))
  65.             Case "BLACK"
  66.                 new_name = new_name & "-" & "k"
  67.             Case "CYAN"
  68.                 new_name = new_name & "-" & "c"
  69.             Case "MAGENTA"
  70.                 new_name = new_name & "-" & "m"
  71.             Case "YELLOW"
  72.                 new_name = new_name & "-" & "y"
  73.         End Select
  74.         wscript.echo new_name
  75.         input_file.Name = new_name & dot_ext_name
  76.     Else
  77.         wscript.echo input_file.Path & " 解析失败"
  78.     End If
  79. End Sub
复制代码

TOP

返回列表