it certainly pays to describe your problem as clearly as possible.
Option Explicit
On Error Resume Next
Dim objFSO,objFile,objRE,colMatches,oMatches
Dim myFiles, srcFolder, dstFolder,dstFile,line,strToFind,strFileName
Dim pdfBase,xmlBase,i,strFileContents
Dim pdfStore(),pdfFullStore() 'define some array to store paths
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Create regexp
Set objRE = New RegExp
objRE.Global = True
objRE.IgnoreCase = False
objRE.Pattern = "\[@name=(.*?)\]" 'pattern to search for
srcFolder="c:\temp" 'Server source folder location
dstFolder="c:\temp" 'Destination Folder as desired
i=0 'array counter
For Each myFiles In objFSO.GetFolder(srcFolder).Files
If objFSO.GetExtensionName(myFiles) = "pdf" Then
pdfBase = objFSO.GetBaseName(myFiles)
ReDim Preserve pdfStore(i)
ReDim Preserve pdfFullStore(i)
pdfStore(i)=pdfBase
pdfFullStore(i)=myFiles
i=i+1
End If
Next
For Each myFiles In objFSO.GetFolder(srcFolder).Files
If objFSO.GetExtensionName(myFiles) = "xml" Then
xmlBase = objFSO.GetBaseName(myFiles)
For i=LBound(pdfStore) To UBound(pdfStore)
If pdfStore(i) = xmlBase Then
WScript.Echo "found " , xmlBase, pdfStore(i)
Set objFile=objFSO.OpenTextFile(myFiles,1)
strFileContents = objFile.ReadAll
objFile.Close
Set colMatches = objRE.Execute(strFileContents)
Set oMatches = colMatches(1)
If Len(oMatches) = 0 Then
WScript.Echo "@name not found"
Else
strToFind = Replace(oMatches,"[@name='","")
strToFind = Replace(strToFind,"']","")
WScript.Echo "The string to replace is ",strToFind
dstFile = dstFolder&"\"&strToFind
WScript.Echo dstFile
WScript.Echo "Renaming pdf ..."
objFSO.MoveFile pdfFullStore(i),dstFile&".pdf"
End If
Set objFile=Nothing
Set oMatches=Nothing
Set colMatches=Nothing
End If
Next
End If
Next