<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Поиск строки в подкаталогах.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8747&amp;type=atom" />
	<updated>2013-10-11T11:23:04Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8747</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75951#p75951" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>xsanekk пишет:</cite><blockquote><p>Простите за глупый вопрос, но мне не понятно, где вставлять путь f:\AVT\PRJ\ и строка поиска (702)...</p></blockquote></div><p>сохранить скрипт в файл (например 1.vbs) и запустить <br />cscript.exe 1.vbs &quot;f:\AVT\PRJ\&quot;&nbsp; &quot;702&quot;</p><p>ну либо заменить в тексте скрипта<br />WScript.Arguments(0) на &quot;f:\AVT\PRJ\&quot;<br />WScript.Arguments(1) на &quot;702&quot;<br />тогда просто запускать <br />cscript.exe 1.vbs</p><p>да кстати, забыл сказать, поскольку для поиска использованы регулярные выражения, то некоторые символы могут быть восприняты как служебные - их нужно брать в квадратные скобки. Например для поиска строки &quot;(702)&quot; нужно указать <br />&quot;[(]702[)]&quot;. Подробней о служ. символах см. <a href="http://www.script-coding.com/WSH/RegExp.html">http://www.script-coding.com/WSH/RegExp.html</a></p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2013-10-11T11:23:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75951#p75951</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75943#p75943" />
			<content type="html"><![CDATA[<p>Простите за глупый вопрос, но мне не понятно, где вставлять путь f:\AVT\PRJ\ и строка поиска (702)...</p>]]></content>
			<author>
				<name><![CDATA[xsanekk]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27386</uri>
			</author>
			<updated>2013-10-11T06:07:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75943#p75943</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75908#p75908" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>yuriy2000 пишет:</cite><blockquote><p>Поскольку я не знаю какого размера файлы будут анализироваться.</p></blockquote></div><p>Спасибо, ясно.</p><div class="quotebox"><blockquote><p>PS: Проверил на пачке из 3000 HTML файлов (каждый в среднем 5К)&nbsp; разницы не заметил.</p></blockquote></div><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"><p>Они случайно, не в одну строчку <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" />? Если будет 3 файла по 5 Mb — будет заметнее <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" />.</p></div></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2013-10-10T03:21:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75908#p75908</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75906#p75906" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p><strong>yuriy2000</strong>, а почему построчно, а не сразу весь текст?</p></blockquote></div><p>Поскольку я не знаю какого размера файлы будут анализироваться.<br />Можно, конечно считать и весь файл сразу... </p><div class="codebox"><pre><code>
Function FindWordCnt(sFileIn,strWord)
     Dim oFileIn, iCnt, sBuf, oMatch

     iCnt = 0
     With New RegExp
        .Global = True
        .IgnoreCase = True &#039; False для поиска с учетом регистра
    
        Set oFileIn = oFSO.OpenTextFile(sFileIn, 1)
        sBuf = oFileIn.ReadAll &#039; считываем файл целиком
        oFileIn.Close

        .Pattern = strWord 
        if .Test(sBuf) then iCnt = .Execute(sBuf).Count &#039; суммируем кол-во найденных слов
    End With
        
    FindWordCnt = iCnt
End Function 

</code></pre></div><p><em>PS: Проверил на пачке из 3000 HTML файлов (каждый в среднем 5К)&nbsp; разницы не заметил.</em></p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2013-10-10T02:01:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75906#p75906</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75905#p75905" />
			<content type="html"><![CDATA[<p><strong>yuriy2000</strong>, а почему построчно, а не сразу весь текст?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2013-10-09T21:50:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75905#p75905</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75901#p75901" />
			<content type="html"><![CDATA[<p>Что-то типа такого. Для вызова использовать <strong>Cscript.exe</strong><br /></p><div class="codebox"><pre><code>
Option Explicit
Public oFSO     : Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Public iTotal : iTotal=0

if WScript.Arguments.Count&lt;2 then
  WScript.Echo &quot;Вызов: &quot; &amp; WScript.ScriptFullName &amp; &quot; HomeDir String&quot;
  WScript.Echo &quot;  где: &quot;
  WScript.Echo &quot;       HomeDir - начальный каталог&quot;
  WScript.Echo &quot;       String  - строка для поиска&quot;

  Wscript.Quit
end if 


ProcessFolder(oFSO.GetFolder(WScript.Arguments(0)))
WScript.Echo &quot; Итого: &quot; &amp; iTotal

Sub ProcessFolder(Folder)
   Dim iFCnt   
    &#039; рекурсивно просматриваем все подпапки

    Dim SubFolder
    For Each SubFolder In Folder.SubFolders
        ProcessFolder SubFolder
    Next

    &#039; обрабатываем каждый файл 
    Dim File
    For Each File  In Folder.Files
        iFCnt = FindWordCnt(File.Path,WScript.Arguments(1)) 
        if iFCnt&gt;0 then 
             iTotal = iTotal + iFcnt
             WScript.Echo  File.Path &amp; &quot;:&quot; &amp;chr(9)&amp; iFCnt
        end if
    Next

End Sub

Function FindWordCnt(sFileIn,strWord)
     Dim oFileIn, iCnt, sBuf, oMatch

     Set oFileIn = oFSO.OpenTextFile(sFileIn, 1)
     iCnt = 0
     With New RegExp
        .Global = True
        .IgnoreCase = True &#039; False для поиска с учетом регистра
    
        Do
            sBuf = oFileIn.ReadLine &#039; считываем строку из файла 
            .Pattern = strWord 
              if .Test(sBuf) then  
                 iCnt=iCnt + .Execute(sBuf).Count &#039; суммируем кол-во найденных слов
              end if
        Loop Until oFileIn.AtEndOfStream
    End With
        
    oFileIn.Close
    FindWordCnt = iCnt
End Function 
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2013-10-09T18:05:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75901#p75901</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Поиск строки в подкаталогах.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=75867#p75867" />
			<content type="html"><![CDATA[<p>В продолжении темы: http://forum.script-coding.com/viewtopic.php?pid=75866#p75866</p><br /><p>Есть папка, в ней находятся подкаталоги, в подкаталогах находятся файлы одинакового расширения, но разные имена. Необходимо найти какое количество раз повторяется заданное слово во всех файлах данного подкаталога, затем считать имя этого подкаталога и записать в текстовый файл, потом аналогично сделать в следующем каталоге и дописать в файл... Файл получится вида:<br />=======================<br />ИмяКаталога1; КоличествоСлов<br />ИмяКаталога2; КоличествоСлов<br />ИмяКаталогаN; КоличествоСлов<br />=======================<br />Общее количество слов: NNNN</p>]]></content>
			<author>
				<name><![CDATA[xsanekk]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27386</uri>
			</author>
			<updated>2013-10-09T06:05:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=75867#p75867</id>
		</entry>
</feed>
