本帖最后由 czjt1234 于 2012-12-13 09:41 编辑
直接替换当前目录下所有.csv文件里的数据,不做备份
请先在新建文件夹里试验
其中 strPath 可自定义路径- Dim Month(11,1), strRead
-
- strPath = CreateObject("Wscript.Shell").CurrentDirectory
-
- Month(0,0) = "Jan" : Month(0,1) = "01"
- Month(1,0) = "Feb" : Month(1,1) = "02"
- Month(2,0) = "Mar" : Month(2,1) = "03"
- Month(3,0) = "Apr" : Month(3,1) = "04"
- Month(4,0) = "May" : Month(4,1) = "05"
- Month(5,0) = "Jun" : Month(5,1) = "06"
- Month(6,0) = "Jul" : Month(6,1) = "07"
- Month(7,0) = "Aug" : Month(7,1) = "08"
- Month(8,0) = "Sep" : Month(8,1) = "09"
- Month(9,0) = "Qct" : Month(9,1) = "10"
- Month(10,0) = "Nov" : Month(10,1) = "11"
- Month(11,0) = "Dec" : Month(11,1) = "12"
-
- Set objFSO = CreateObject("Scripting.FileSystemObject")
-
- Set objFolder = objFSO.GetFolder(strPath)
- set objFiles = objFolder.Files
-
- for Each objFile In objFiles
- If LCase(Right(objFile.Name, 3)) = "csv" Then
- With objFSO.OpenTextFile(objFile.Name, 1)
- strRead = .ReadAll
- .Close
- End With
-
- For i = 0 To 11
- With New RegExp
- .IgnoreCase = True
- .Global = True
- .Pattern = Month(i,0)
- strRead = .Replace(strRead, Month(i,1))
- End With
- Next
-
- With objFSO.OpenTextFile(objFile.Name, 2)
- .Write strRead
- .Close
- End With
-
- Msgbox objFile.Name & " 替换完毕。"
- End If
- Next
复制代码
|