《hoge.vbs》
Set FSO = CreateObject("Scripting.FileSystemObject")
Set RO = New RegExp
RO.IgnoreCase = True
Set Input = FSO.OpenTextFile("tmp.txt")
Set Output = FSO.CreateTextFile("jwc_temp.txt",True)
Input.ReadLine
Output.WriteLine "hd"
While Input.AtEndOfStream <> TRUE
Buf = Input.ReadLine
If InStr(Buf,"^@BM") <> 0 Then
TopOfLine = Left(Buf,InStr(Buf,"^@BM")+3)
Buf = Mid(Buf,Len(TopOfLine)+1)
EndOfLine = Mid(Buf,InStr(Buf,","))
RO.Pattern = ",[^,]+,[^,]+$"
Set Matches = RO.Execute(Buf)
For Each Match in Matches
EndOfLine = Match.Value
Next
If FSO.GetDriveName(Buf) = FSO.GetDriveName(JwwDirPath) Then
RO.Pattern = ",[^,]+,[^,]+$"
ImgFilePath = RO.Replace(Buf,"")
ImgDirPath = FSO.GetParentFolderName(ImgFilePath)
Buf = TopOfLine & RelativePath(JwwDirPath,ImgDirPath) & FSO.GetFileName(ImgFilePath) & EndOfLine
Else
Buf = TopOfLine & Buf
End If
ElseIf InStr(Buf,"file=") = 1 Then
JwwFilePath = Mid(Buf,InStr(Buf,"=")+1)
JwwDirPath = Left(JwwFilePath,InStrRev(JwwFilePath,"\"))
End If
Output.WriteLine Buf
Wend
Input.Close
Output.Close
Function RelativePath(BasePath,SubPath)
BasePathArray = Split(BasePath,"\",-1,vbTextCompare)
SubPathArray = Split(SubPath,"\",-1,vbTextCompare)
If UBound(BasePathArray) < UBound(SubPathArray) Then
iCount = UBound(BasePathArray)
Else
iCount = UBound(SubPathArray)
End If
RelativePath = ""
For i = 0 To iCount
If BasePathArray(i) <> SubPathArray(i) Then
For j = UBound(BasePathArray) to i+1 Step -1
RelativePath = RelativePath & "..\"
Next
Exit For
Else
SubPathArray(i) = ""
End If
Next
For i = 0 To UBound(SubPathArray)
If SubPathArray(i) <> "" Then
RelativePath = RelativePath & SubPathArray(i) & "\"
End If
Next
End Function