<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: Поиск текста и его замена в документах]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=14915</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14915&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: Поиск текста и его замена в документах».]]></description>
		<lastBuildDate>Sun, 11 Aug 2019 00:58:18 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135452#p135452</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (biffick)]]></author>
			<pubDate>Sun, 11 Aug 2019 00:58:18 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135452#p135452</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135451#p135451</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (alexii)]]></author>
			<pubDate>Sat, 10 Aug 2019 22:43:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135451#p135451</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135449#p135449</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (biffick)]]></author>
			<pubDate>Sat, 10 Aug 2019 20:07:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135449#p135449</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135448#p135448</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (alexii)]]></author>
			<pubDate>Sat, 10 Aug 2019 19:29:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135448#p135448</guid>
		</item>
		<item>
			<title><![CDATA[CMD/BAT: Поиск текста и его замена в документах]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=135438#p135438</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (biffick)]]></author>
			<pubDate>Sat, 10 Aug 2019 09:15:40 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=135438#p135438</guid>
		</item>
	</channel>
</rss>
