像这样的东西..未经测试,但应该为您指明正确的方向
Option Explicit
Dim fileCount
Sub ProcessSubDirectory( ByVal directory)
On Error Resume Next
Dim fso
Dim dir
Dim folder
Dim file
Set fso = CreateObject("Scripting.FileSystemObject")
Set dir = fso.GetFolder(directory)
If Err.Number <> 0 THen
MsgBox "Failed to open dir ( " & directory & " )"
Exit Sub
End If
On Error Goto 0
For Each file in dir.Files
Call HandleFileFix( file.Path )
Next
For Each folder in dir.SubFolders
Call ProcessSubDirectory( folder.Path )
Next
Set fso = Nothing
End Sub
Sub HandleFileFix( ByVal file)
Dim fso
Dim f
Dim fo
Dim contents
DIm path
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFile( file )
Set f = fso.OpenTextFile( file, 1 )
path = fo.Path
path = Replace( path, fo.Drive, "")
path = Replace( path, fo.Name, "")
path = Replace( path, "\", "/")
If f.AtEndOfStream = false then
contents = f.ReadAll
End If
f.Close
Set f = Nothing
contents = Replace( contents, "='img/", "='" & path & "/img/")
' write file back to disk
Set f = fso.OpenTextFile( file, 2 )
f.Write contents
f.Close
fileCount = fileCount + 1
Set f = Nothing
End Sub
fileCount = 0
Call ProcessSubDirectory( "D:\TEST\" )
MsgBox "done (" & CStr(fileCount) & ")"