<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Поиск текста и его замена в документах]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14915&amp;type=atom" />
	<updated>2019-08-11T00:58:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14915</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=135452#p135452" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Скажем так — возможностей на порядок меньше, код намного сложнее, и ряд сложно решаемых проблем с некоторыми символами.</p></blockquote></div><p>Понял</p><p>Спасибо за скрипт <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Работает хорошо <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[biffick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40335</uri>
			</author>
			<updated>2019-08-11T00:58:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=135452#p135452</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=135451#p135451" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>biffick пишет:</cite><blockquote><p> т.е. батником такое дело в принципе не реализовать?</p></blockquote></div><p>Скажем так — возможностей на порядок меньше, код намного сложнее, и ряд сложно решаемых проблем с некоторыми символами.</p><div class="quotebox"><cite>biffick пишет:</cite><blockquote><p> подскажите, правильная кодировка для VBS-скриптов - 1251?</p></blockquote></div><p>Да.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2019-08-10T22:43:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=135451#p135451</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=135449#p135449" />
			<content type="html"><![CDATA[<p><strong>alexii</strong>, т.е. батником такое дело в принципе не реализовать?<br />UPD: проверил скрипт - работает на ура, большое спасибо!<br />UPD 2: подскажите, правильная кодировка для VBS-скриптов - 1251? Просто в UTF-8 и OEM-866 я получаю иероглифы при выводе информационных сообщений <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[biffick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40335</uri>
			</author>
			<updated>2019-08-10T20:07:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=135449#p135449</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=135448#p135448" />
			<content type="html"><![CDATA[<p>Скажу сразу — пакетные файлы для этого не годятся.</p><p>Вот Вам примерный код на WSH:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>Option Explicit

Const ForAppending = 8


Dim arrSourceFiles
Dim strString4Find
Dim strString4Replace
Dim boolIsCaseReplacing
Dim boolIsLogging
Dim strPath2LogFile

Dim objFSO
Dim strSourceFile
Dim strContent
Dim boolFound


arrSourceFiles      = Array( _
	&quot;C:\Folder 1\File.php&quot;, _
	&quot;C:\Folder 2\Folder3\File.txt&quot;, _
	&quot;C:\File.ini&quot; _
)

strString4Find      = &quot;10.10.10.10&quot;
strString4Replace   = &quot;11.11.11.11&quot;
boolIsCaseReplacing = True

boolIsLogging       = True
strPath2LogFile     = &quot;C:\replace.log&quot;


Set objFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)

If boolIsLogging Then
	If Not objFSO.FolderExists(objFSO.GetParentFolderName(strPath2LogFile)) Then
		WScript.Echo &quot;Can&#039;t find logging folder [&quot; &amp; objFSO.GetParentFolderName(strPath2LogFile) &amp; &quot;].&quot;
		WScript.Quit 1
	End If
End If

For Each strSourceFile In arrSourceFiles
	If objFSO.FileExists(strSourceFile) Then
		With objFSO.OpenTextFile(strSourceFile)
			strContent = .ReadAll()
			.Close
		End With
		
		boolFound = False
		
		If boolIsCaseReplacing Then
			If InStr(1, strContent, strString4Find, vbTextCompare) &gt; 0 Then
				boolFound  = True
				strContent = Replace(strContent, strString4Find, strString4Replace, 1, -1, vbTextCompare)
			End If
		Else
			If InStr(1, strContent, strString4Find, vbBinaryCompare) &gt; 0 Then
				boolFound  = True
				strContent = Replace(strContent, strString4Find, strString4Replace, 1, -1, vbBinaryCompare)
			End If
		End If
		
		If boolFound Then
			With objFSO.CreateTextFile(strSourceFile, True)
				.Write strContent
				.Close
			End With
			
			LogOut &quot;Found [&quot; &amp; strString4Find &amp; &quot;] in source file [&quot; &amp; _
				strSourceFile &amp; &quot;] and replaced by [&quot; &amp; strString4Replace &amp; &quot;].&quot;
		Else
			LogOut &quot;Nothing found in source file [&quot; &amp; strSourceFile &amp; &quot;].&quot;
		End If
	Else
		LogOut &quot;Can&#039;t find source file [&quot; &amp; strSourceFile &amp; &quot;].&quot;
	End If
Next

Set objFSO = Nothing

WScript.Quit 0
&#039;=============================================================================

&#039;=============================================================================
Sub LogOut(strValue)
	WScript.Echo strValue
	
	If boolIsLogging Then
		With objFSO.OpenTextFile(strPath2LogFile, ForAppending, True)
			.WriteLine Now() &amp; vbTab &amp; strValue
			.Close
		End With
	End If
End Sub
&#039;=============================================================================
</code></pre></div></div></div><p>P.S. Само собой, писать что-то в корень раздела системного диска — моветон.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2019-08-10T19:29:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=135448#p135448</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=135438#p135438" />
			<content type="html"><![CDATA[<p>Всем привет, может кто поможет со скриптом для домашнего сервера? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Нужно, чтобы скрипт находил текст в файлах и заменял на другой кусок текста (не целую строку, а именно кусок текста, который может быть в любом месте файла).<br />Очень важно добавить параметр, который отвечал бы за поиск с учётом регистра и без него.</p><p>Каркас нужен такой:</p><div class="codebox"><pre><code>Log=True ; Логировать ли действия скрипта
Logfile=&quot;C:\replace.log ; Путь и название файла лога

CaseSens=True/False ; Учитывать ли регистр при поиске текста

Find=&quot;10.10.10.10&quot; ; Что нужно найти
Replace=&quot;11.11.11.11&quot; ; Чем нужно заменить найденное

Path1=&quot;C:\Folder 1\File.php&quot; ; Путь к файлу №1, в котором нужно искать и заменять текст
Path2=&quot;C:\Folder 2\Folder3\File.txt&quot; ; Путь к файлу №2, в котором нужно искать и заменять текст
Path3=&quot;C:\File.ini&quot; ; Путь к файлу №3, в котором нужно искать и заменять текст</code></pre></div>]]></content>
			<author>
				<name><![CDATA[biffick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40335</uri>
			</author>
			<updated>2019-08-10T09:15:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=135438#p135438</id>
		</entry>
</feed>
