Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Скрытый текст
Код: Выделить весь код
Option Explicit

Dim strSourceFile
Dim strPatternFile
Dim strDestFile

Dim strContent
Dim strLine
Dim arrPattern

Dim objDictionary
Dim strKey


strSourceFile  = "C:\Мои проекты\0053\build.prop"
strPatternFile = "C:\Мои проекты\0053\path.txt"
strDestFile    = "C:\Мои проекты\0053\new_build.prop"



With WScript.CreateObject("Scripting.FileSystemObject")
	If .FileExists(strSourceFile) Then
		If .FileExists(strPatternFile) Then
			With .OpenTextFile(strPatternFile)
				strContent = .ReadAll()
				.Close
			End With
			
			Set objDictionary = WScript.CreateObject("Scripting.Dictionary")
			
			For Each strLine In Split(strContent, vbLf)
				strLine = Trim(strLine)
				
				If Len(strLine) > 0 Then
					arrPattern = Split(strLine, "=")
					objDictionary.Add Trim(arrPattern(0)), Trim(arrPattern(1))
				End If
			Next
			
			With .OpenTextFile(strSourceFile)
				strContent = .ReadAll()
				.Close
			End With
			
			With WScript.CreateObject("VBScript.RegExp")
				.IgnoreCase = True
				.Global     = True
				
				For Each strKey In objDictionary.Keys
					.Pattern = "[\f\t\v]*(" & strKey & ")[\f\t\v]*=[\f\t\v]*?.*[\f\t\v]*"
					
					If .Test(strContent) Then
						strContent = .Replace(strContent, "$1=" & objDictionary.Item(strKey))
					End If
				Next
			End With
			
			With .CreateTextFile(strDestFile, True)
				.Write strContent
				.Close
			End With
			
			objDictionary.RemoveAll
			Set objDictionary = Nothing
		Else
			WScript.Echo "Can't find pattern file [" & strPatternFile & "]."
			WScript.Quit 2
		End If
	Else
		WScript.Echo "Can't find source file [" & strSourceFile & "]."
		WScript.Quit 1
	End If
End With

WScript.Quit 0

Вообще-то, патч по-англицки именуется «patch».
Это сообщение посчитали полезным следующие участники:

Отправлено: 07:19, 19-03-2017 | #2