原先的回数,全是汉语数字,为此我先转换成了阿拉伯数字,遗憾的是阿拉伯数字100居然排在1和2之前!所以必须设置为3位数字才行!否则顺序是乱的。
以下是用VBA批量重命名的代码:
Dim FSO As New FileSystemObject
Dim fd As Folder, fl As File
Sub Test()On Error Resume NextFor Each fd In FSO.GetFolder("E:\Office_VBA\历朝通俗演义").SubFoldersFor Each fl In fd.Filesfl.Name = D2N(fl.Name)Debug.Print fl.NameNext flNext fd
End Sub
Function C2N(Source As String) As StringConst nine = "一二三四五六七八九"Dim temp As StringDim num As IntegerIf Source Like "自序*" Thentemp = "第0回 " & SourceC2N = tempExit FunctionEnd Iftemp = Split(Source, "回")(0)temp = Split(temp, "第")(1)If InStr(temp, "百") > 0 Thennum = 100temp = Right(temp, Len(temp) - 2)End IfIf InStr(temp, "十") = 1 Thennum = num + 10temp = Right(temp, Len(temp) - 1)End IfIf InStr(temp, "十") > 1 Thennum = num + 10 * InStr(nine, Left(temp, 1))temp = Right(temp, Len(temp) - 2)End IfIf temp <> "" Thennum = num + InStr(nine, Left(temp, 1))End IfC2N = "第" & num & "回" & Split(Source, "回")(1)
End Function
Function D2N(Source As String) As StringDim temp As Stringtemp = Split(Source, "回")(0)temp = Split(temp, "第")(1)temp = Format(temp, "000")D2N = "第" & temp & "回" & Split(Source, "回")(1)
End Function
下载:
历朝通俗演义
下载后,必须解压缩,然后双击exe文件即可启动。