【发布时间】:2014-07-03 21:31:29
【问题描述】:
我有很多文件夹,每个文件夹中都有许多 HTML 文件,一个文件夹中有多达 70 个文件,我请朋友帮我对这些文件进行批量编辑,以将它们的背景和字体颜色更改为以及在底部添加一个链接以转到文件夹中的下一个文件,这是他发给我的 .. 这是一个 .vbs 文件
'Here are the settings
'Be warned this is old fashioned preHTML5 stuff no css. But well I guess it could be implemented as well
'I think most of the replacements are pretty straight forward
'Run this script in a folder with all the files for one story
'Running it more then once can have unforseen consequences :)
background="black"
foreground="white"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSuperFolder = objFSO.GetFolder(".")
Call ShowFiles (objSuperFolder)
WScript.Quit 0
Sub ShowFiles(fFolder)
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
Dim a(50000)
Dim b(50000)
i = 1
For Each objFile In colFiles
If UCase(objFSO.GetExtensionName(objFile.name)) = "HTML" Then
a(i) = objFile.Path
b(i)=objFile.Name
i = i + 1
End If
Next
j=i
For z = 1 To j-1
Set objFile2 = objFSO.OpenTextFile(a(z), 1)
strText = objFile2.ReadAll
strText = Replace(strText, "<body>", "<body bgcolor=""" +background+""">")
strText = Replace(strText, "<html>", "<html><font color=""" +foreground+""">")
strText = Replace(strText, "</html>", "</font></html>")
'Add the link to next chapter
If z < j-1 Then
strText = Replace(strText,"</body>","<a href="""+b(z+1)+""">Link to next chapter!</a></body>")
End If
objFile2.Close
Set objFile2 = objFSO.OpenTextFile(a(z), 2)
objFile2.Write strText
objFile2.Close
Next
End Sub
并且在大多数情况下它工作得很好,除了它将 1 链接到 10 然后 11、12、... 19、2、20、21 等等我试图弄清楚如何修复它,所以链接从 1 到 2, 3, ... 9, 10, 11... 除了末尾的数字外,给定文件夹中的 HTML 文件名都相同 名称0.html 名称1.html 名称2.html ... 名称9.html 名称10.html 名称11.html ETC... 顺便说一句,html文件是由我下载的程序生成的,所以如果出现错误,我可以很容易地重新创建它们哦,我也想添加更改字体大小,但如果太麻烦,我可以轻松地继续使用缩放解决该问题的功能
在回应第一个答案时添加:
不,我无法控制原始程序编号的输出,但如果有人有一个快速 VBS 脚本将文件更改为 3 位数格式的数字,那将是一个可爱的解决方案
http://helloacm.com/bubble-sort-in-vbscript/ 这看起来可能是朝着正确方向迈出的一步? Sorting arrays numerically and alphabetically(like Windows Explorer) without using StrCmpLogicalW or shlwapi.dll - ASP.NET VB 还是这个?
【问题讨论】: