我正在處理腳本,如果沒有您的幫助,我將無法創建它。 這就是我需要:我有兩個.txt文件,一個包含變量(二@
之間),像這樣:使用VBS替換兩個文件之間的變量值
@[email protected]=E:/SonicDataFiles/AR_INT/GPP_VE/IN
@[email protected]=jdbc:sonic:sqlserver://CARASETMS:1433;databaseName=CRM
其他的.txt有需要從以前的文件完成變量
@[email protected]=
@[email protected]=
我需要得到第一個文件中的每個變量(我想我必須使用正則表達式),並在第二個文件中替換它的值,如果變量退出。
我真的很感激,如果有人有類似的腳本來得到一個想法。我試圖用VBS來做。
非常感謝。
赫拉爾多。
布宜諾斯艾利斯,阿根廷。
這是我原來的劇本:
'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, "@[email protected]=")
vPickupFolder = InStr(strSearchString, "@[email protected]=")
vDbUrl = InStr(strSearchString, "@[email protected]=")
vDbPwd = InStr(strSearchString, "@[email protected]=")
vDbUser = InStr(strSearchString, "@[email protected]=")
vDbDestTable = InStr(strSearchString, "@[email protected]=")
'PARSE OUT THE NEEDED INFO
If vQuartz <> 0 Then
'vQuartz = vQuartz + 13
strQuartz = Mid(strSearchString, vQuartz, 304)
' WScript.Echo strQuartz
End If
If vPickupFolder <> 0 Then
'vPickupFolder = vPickupFolder + 15
strPickupfFolder = Mid(strSearchString, vPickupFolder, 50)
' WScript.Echo strPickupfFolder
End If
If vDbUrl <> 0 Then
'vDbUrl = vDbUrl + 9
strUrl = Mid(strSearchString, vDbUrl, 65)
' WScript.Echo strUrl
End If
If vDbPwd <> 0 Then
'vDbPwd = vDbPwd + 9
strDbPwd = Mid(strSearchString, vDbPwd, 17)
'WScript.Echo strDbPwd
End If
If vDbUser <> 0 Then
'vDbUser = vDbUser + 10
strDbUser = Mid(strSearchString, vDbUser, 25)
'WScript.Echo strDbUser
End If
If vDbDestTable <> 0 Then
'vDbDestTable = vDbDestTable + 19
strDbDestTable = Mid(strSearchString, vDbDestTable, 29)
'WScript.Echo strDbDestTable
End If
objFileVariablesTXT.Close
strReplaceString = objFileTailoring.ReadAll
arrReplacements = Array("@[email protected]=Ç" & strQuartz , "@[email protected]=Ç" & strPickupfFolder, "@[email protected]=Ç" & strUrl, "@[email protected]=Ç" & strDbPwd, "@[email protected]=Ç" &strDbUser, "@[email protected]=Ç" & 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
感謝讓 - 弗朗索瓦。 是的,我已經創建了一個腳本,但我的問題是,我需要一個腳本來查找文件中的每個變量,我對它們的名字進行了硬編碼以搜索它們 – Gerardo