title: Replace variables values between two files using VBS
body: <p>I'm dealing with a script and I won't be able to create it without your help.
  This is what I need: I have two .txt files, one contains variables (between two <code>@</code>) like these:</p>
  
  <pre><code>@PickupFolder@=E:/SonicDataFiles/AR_INT/GPP_VE/IN           
  @Db1Url@=jdbc:sonic:sqlserver://CARASETMS:1433;databaseName=CRM
  </code></pre>
  
  <p>The other .txt have variables that need to be completed from the previous file</p>
  
  <pre><code>@Db1Url@=
  @Db1Pwd@=
  </code></pre>
  
  <p>I need to get every variable in the first file (I guess I have to use regular expression) and replace its value in the second file if the variable exits.</p>
  
  <p>I would really appreciate if anyone has a similar script to get an idea. I'm trying to do it with VBS.</p>
  
  <p>Thanks a lot.</p>
  
  <p>Gerardo.<br>
  Buenos Aires, Argentina.</p>
  
  <p>This was my original script:</p>
  
  <pre><code>            'ReplaceScript "c:\Variables_INT.txt" "C:\AR_INT.tailoring.properties"
  
              'DEFINE CONSTANTS
              Const ForReading = 1
              Const ForWriting = 2
              Const ForAppending = 8
  
              'DEFINE VARIABLES
              strTxtFile = Wscript.Arguments(0)
              strTailoringFile = Wscript.Arguments(1)
              Set objFSO = CreateObject("Scripting.FileSystemObject")
              Set WshShl = WScript.CreateObject("WScript.Shell")
              Set objFileVariablesTXT = objFSO.OpenTextFile (strTxtFile, ForReading)                      'Variables_INT.txt
              Set objFileTailoring = objFSO.OpenTextFile (strTailoringFile, ForReading)                   'AR_INT.tailoring.properties
              Dim strQuartz, strPickupfFolder, strUrl, strDbPwd, strDbUser, strDbDestTable
  
              strSearchString = objFileVariablesTXT.ReadAll
              'SEARCH THE FILE FOR THE NEEDED DATA
                  vQuartz = InStr(strSearchString, "@QuartzJars@=")
                  vPickupFolder = InStr(strSearchString, "@PickupFolder@=")
                  vDbUrl = InStr(strSearchString, "@Db1Url@=")
                  vDbPwd = InStr(strSearchString, "@Db1Pwd@=")
                  vDbUser = InStr(strSearchString, "@Db1User@=")
                  vDbDestTable = InStr(strSearchString, "@DestinationTable@=")
  
              'PARSE OUT THE NEEDED INFO
                  If vQuartz &lt;&gt; 0 Then
                      'vQuartz = vQuartz + 13
                      strQuartz = Mid(strSearchString, vQuartz, 304)
                          ' WScript.Echo strQuartz
                 End If 
                 If vPickupFolder &lt;&gt; 0 Then
                      'vPickupFolder = vPickupFolder + 15
                      strPickupfFolder = Mid(strSearchString, vPickupFolder, 50)
                       '    WScript.Echo strPickupfFolder
                 End If 
                 If vDbUrl &lt;&gt; 0 Then
                      'vDbUrl = vDbUrl + 9
                      strUrl = Mid(strSearchString, vDbUrl, 65)
                         '  WScript.Echo strUrl
                 End If 
                 If vDbPwd &lt;&gt; 0 Then
                      'vDbPwd = vDbPwd + 9
                      strDbPwd = Mid(strSearchString, vDbPwd, 17)
                           'WScript.Echo strDbPwd
                 End If 
                 If vDbUser &lt;&gt; 0 Then
                      'vDbUser = vDbUser + 10
                      strDbUser = Mid(strSearchString, vDbUser, 25)
                           'WScript.Echo strDbUser
                 End If 
                 If vDbDestTable &lt;&gt; 0 Then
                      'vDbDestTable = vDbDestTable + 19
                      strDbDestTable = Mid(strSearchString, vDbDestTable, 29)
                           'WScript.Echo strDbDestTable
                 End If 
  
              objFileVariablesTXT.Close
  
  
              strReplaceString = objFileTailoring.ReadAll
  
  
              arrReplacements = Array("@QuartzJars@=Ç" &amp; strQuartz , "@PickupFolder@=Ç" &amp; strPickupfFolder, "@Db1Url@=Ç" &amp; strUrl, "@Db1Pwd@=Ç" &amp; strDbPwd, "@Db1User@=Ç" &amp;strDbUser, "@DestinationTable@=Ç" &amp; strDbDestTable)
  
              objFileTailoring.Close
  
              Set objFileTailoring = Nothing
  
              For Each strReplacement In arrReplacements
                      strReplaceWhat = Split(strReplacement, "Ç")(0)
                      'WScript.Echo strReplaceWhat
                      strReplaceWith = Split(strReplacement, "Ç")(1)
                      'WScript.Echo strReplaceWith
                      strReplaceString = Replace(strReplaceString, strReplaceWhat, strReplaceWith)
              Next
              'wScript.Echo strReplaceString
  
              Set objFileTailoring = objFSO.OpenTextFile(strTailoringFile, 2, true)
              objFileTailoring.Write strReplaceString
  
              objFileTailoring.Close
  </code></pre>