|
给一个另类解
假设列表文件list.txt,待搜索文件夹D:\ABC,代码保存为test.bat与list.txt放在一起
- Set re=Nothing ''&cls&dir /a-d/b/s "D:\ABC"|cscript -nologo -e:vbscript "%~f0" &pause&exit/b
- Set fso = CreateObject("Scripting.FileSystemObject")
- s = WScript.StdIn.ReadAll
- Set file = fso.OpenTextFile("List.txt", 1)
- while not file.AtEndOfStream
- strLine = Trim(file.ReadLine)
- If strLine <> "" Then
- name = fso.GetBaseName(strLine)
- ext = fso.GetExtensionName(strLine)
- pattern = "(.+\\).*" & name & "[^\\]*\." & ext
- RenMyFile pattern, name, "." & ext
- End If
- wend
- Sub RenMyFile(strPattern, strName, strExt)
- Set re = New RegExp
- re.Pattern = strPattern
- re.Global = true
- re.IgnoreCase = true
- For Each m In re.Execute(s)
- path = m.SubMatches(0)
- strNewName = strName & strExt
- n = 0
- while fso.FileExists(path & strNewName)
- n = n + 1
- strNewName = strName & "-" & n & strExt
- wend
- fso.GetFile(m).Name = strNewName
- Next
- End Sub
复制代码 |
评分
-
查看全部评分
|