vbs版的,需要安装office- Dim p, oFSO, s, TCSC
-
- p = "." '当前目录,可改为其它路径,比如 D:\test\
-
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set TCSC = New TCSCConverter
- s = ""
- Call EnumFiles(oFSO.GetFolder(oFSO.GetAbsolutePathName(p)).Path)
- For Each i In SPlit(Left(s, Len(s) - 2), vbCrLf)
- oFSO.MoveFile i, TCSC.TC2SC(i)
- Next
-
- Class TCSCConverter
- Private Word, Doc
-
- 'Author: Demon
- 'Date: 2011/12/13
- 'Website: https://demon.tw
-
- Private Sub Class_Initialize()
- Set Word = CreateObject("Word.Application")
- End Sub
-
- Private Sub Class_Terminate()
- Word.Quit
- Set Word = Nothing
- End Sub
-
- 'Traditional Chinese To Simplified Chinese
- Public Function TC2SC(str)
- Set Doc = Word.Documents.Add
- Word.Selection.TypeText str
- Doc.Range.TCSCConverter 1, True
- TC2SC = Replace(Doc.Range.Text, vbCr, vbCrLf)
- TC2SC = Left(TC2SC, Len(TC2SC) - 2)
- Doc.Saved = True
- Doc.Close
- Set Doc = Nothing
- End Function
-
- 'Simplified Chinese To Traditional Chinese
- Public Function SC2TC(str)
- Set Doc = Word.Documents.Add
- Word.Selection.TypeText str
- Doc.Range.TCSCConverter 0, True, True
- SC2TC = Replace(Doc.Range.Text, vbCr, vbCrLf)
- SC2TC = Left(SC2TC, Len(SC2TC) - 2)
- Doc.Saved = True
- Doc.Close
- Set Doc = Nothing
- End Function
- End Class
-
- Sub EnumFiles(ByVal folderPath)
- Dim oFile, oFolder 'oFSO, s 是全局变量
- On Error Resume Next '忽略无权限读取的文件夹和文件
- For Each oFile In oFSO.GetFolder(folderPath).Files
- s = s & oFile.Path & vbCrLf
- Next
- For Each oFolder In oFSO.GetFolder(folderPath).SubFolders
- Call EnumFiles(oFolder.Path)
- Next
- End Sub
复制代码
|