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

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

Ветеран


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

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


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

Const ForWriting = 2

Dim strSourceFile
Dim strPatternFile

Dim strContent
Dim strLine

Dim objDictionary
Dim strKey


strSourceFile =  "C:\Мои проекты\36\1.txt"
strPatternFile = "C:\Мои проекты\36\2.txt"

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, vbCrLf)
				strLine = Trim(strLine)
				
				If Len(strLine) > 0 Then
					objDictionary.Add .GetFileName(strLine), strLine
				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 = "(<a href="")(http://.*?/" & strKey & ")("".*?>.*?</a>)"
					
					If .Test(strContent) Then
						strContent = .Replace(strContent, "$1" & objDictionary.Item(strKey) & "$3")
					End If
				Next
			End With
			
			.CopyFile strSourceFile, .BuildPath(.GetParentFolderName(strSourceFile), .GetBaseName(strSourceFile) & ".bak"), True
			
			With .OpenTextFile(strSourceFile, ForWriting)
				.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
Это сообщение посчитали полезным следующие участники:

Отправлено: 08:30, 14-02-2016 | #2