<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Поиск последней строки в .txt]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=13914&amp;type=atom" />
	<updated>2018-07-08T20:21:10Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=13914</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126840#p126840" />
			<content type="html"><![CDATA[<p>Можно, но такой ерундой никто не будет заниматся.<br />Вы хотите простое сделать сложным. Лучше поясните что имеется, и что нужно в итоге.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-07-08T20:21:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126840#p126840</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126816#p126816" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong> Маленькое продолжение темы.<br /></p><div class="codebox"><pre><code>
varX := NeedLine(A_ScriptFullPath, -4)
varY := NeedLine(A_ScriptFullPath, -6)

Gui, Show, x%varX% y%varY%

NeedLine(FilePath, Line) {
	FileRead, Text, usa.txt
	Text := StrReplace(StrReplace(Text, &quot;`r`n&quot;, &quot;`n&quot;), &quot;`r&quot;, &quot;`n&quot;) &quot;`n&quot;
	s := InStr(Text, &quot;`n&quot;, 0, (Line &gt; 0), Abs(Line - 1)) + 1 
	Return SubStr(Text, s, InStr(Text, &quot;`n&quot;, 0, (Line &gt; 0), Abs(Line)) - s)
}
</code></pre></div><p>Такое вообще возможно сделать, чтобы функция NeedLine читала текст не с текстового документа, а с Gui, и Text, в котором и присутствуют строки (которые будут читаться функцией) будет выводиться как координаты в Gui, Show.<br />p.s Старался как можно внятней изложить мою мысль.</p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-08T10:03:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126816#p126816</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126786#p126786" />
			<content type="html"><![CDATA[<p><strong>alexii</strong>, спасибо, гляну.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-07-07T13:12:36Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126786#p126786</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126785#p126785" />
			<content type="html"><![CDATA[<p>OFF:<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>OFF: Если файл очень большой, и нужно прочитать определённую строчку с конца, то наиболее экономичным способом будет что-то вроде этого:</p></blockquote></div><p>А не хотите OLE DB опробовать, как здесь: <a href="http://forum.script-coding.com/viewtopic.php?id=1322">VBScript: работа с большими текстовыми файлами</a>? AHK ж уже давно научился в Automation. Конечно, файлы должны быть реально <em>большими</em>, бо с нынешними гигабайтами оперативной памяти и ReadAll не слишком медленно будет.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2018-07-07T13:10:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126785#p126785</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126783#p126783" />
			<content type="html"><![CDATA[<p>OFF: Если файл очень большой, и нужно прочитать определённую строчку с конца, то наиболее экономичным способом будет что-то вроде этого:<br /></p><div class="codebox"><pre><code>FileReadLineFromEnd(filePath, nLineFromEnd)  {
   oFile := FileOpen(filePath, &quot;r&quot;)
   oFile.Pos := oFile.Length
   (!(enc := oFile.Encoding) &amp;&amp; enc := &quot;cp0&quot;)
   charLen := enc = &quot;UTF-16&quot; ? 2 : 1
   i := 0
   Loop  {
      oFile.Pos -= charLen, prevPos := oFile.Pos
      if (oFile.Pos &lt; 0 &amp;&amp; notFound := true)
         break
      char := oFile[ &quot;Read&quot; . (enc = &quot;UTF-16&quot; ? &quot;UShort&quot; : &quot;UChar&quot;) ]()
      if (char = 10 || char = 13)  {
         if ( prevChar = (char = 10 ? 13 : 10) )
            prevChar := &quot;&quot;
         else
            i++, prevChar := char
      }
      if (i = nLineFromEnd)
         break
      oFile.Pos := prevPos
   }
   ( !notFound &amp;&amp; str := oFile.ReadLine() ), oFile.Close()
   Return RTrim(str, &quot;`r`n&quot;)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-07-07T13:00:48Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126783#p126783</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126779#p126779" />
			<content type="html"><![CDATA[<p>Если пробел поставить, то должно работать.<br /></p><div class="codebox"><pre><code>x%varX%y%varY%</code></pre></div><div class="codebox"><pre><code>
varX := NeedLine(A_ScriptFullPath, -4)
varY := NeedLine(A_ScriptFullPath, -6)
MsgBox % varX &quot;`n&quot; varY

Gui, Add, Button, x%varX% y%varY%, Button

NeedLine(FilePath, Line) {
	FileRead, Text, %FilePath%
	Text := StrReplace(StrReplace(Text, &quot;`r`n&quot;, &quot;`n&quot;), &quot;`r&quot;, &quot;`n&quot;) &quot;`n&quot;
	s := InStr(Text, &quot;`n&quot;, 0, (Line &gt; 0), Abs(Line - 1)) + 1 
	Return SubStr(Text, s, InStr(Text, &quot;`n&quot;, 0, (Line &gt; 0), Abs(Line)) - s)
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-07-07T11:27:30Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126779#p126779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126773#p126773" />
			<content type="html"><![CDATA[<p>Так зачем так читать, если есть IniRead. И почему A_ScriptFullPath, если тогда в самом скрипте они могут быть прописаны как переменные.<br />Как же сильно я промахнулся с предположением про лог файл.)</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-07-07T10:47:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126773#p126773</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126772#p126772" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong> Функция считывает с конца файла 2 строки, в которых указаны 2-е координат.<br />.<br /></p><div class="codebox"><pre><code>varX := % NeedLine(A_ScriptFullPath, 4)</code></pre></div><p>и<br /></p><div class="codebox"><pre><code>varY := % NeedLine(A_ScriptFullPath, 6)</code></pre></div><p>Координаты кнопке устанавливаем как<br /></p><div class="codebox"><pre><code>Gui, Add, Button, x%varX%y%varY%, Button</code></pre></div><p>Но так - не выходит.</p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-07T10:43:05Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126772#p126772</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126771#p126771" />
			<content type="html"><![CDATA[<p>Не понял.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-07-07T10:39:01Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126771#p126771</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126770#p126770" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong> А эту функцию можно засунуть под </p><div class="codebox"><pre><code>var := % NeedLine(A_ScriptFullPath, -1)</code></pre></div><p> ; например??</p>]]></content>
			<author>
				<name><![CDATA[MirchikAhtung]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=38635</uri>
			</author>
			<updated>2018-07-07T10:37:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126770#p126770</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126769#p126769" />
			<content type="html"><![CDATA[<p>Я просто добавил чтобы было понятно как определять если запрос превышает кол-во строк.<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Или так:</p></blockquote></div><p>Я тоже сразу подумал про StrSplit, но загонять в массив например 5000 строк ради вывода одной, кажется избыточным.<br />Наверняка ТС читает какой нибудь лог, и он со временем разрастается. Когда речь про какие нибудь последние строки в файле, это похоже на поиск новой инфо в логе, тогда <a href="http://forum.script-coding.com/viewtopic.php?pid=95324#p95324">проще так</a>.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-07-07T10:30:00Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126769#p126769</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126764#p126764" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>И добавить если указанная строка больше кол-ва строк в тексте, то при запросе назад показать первую строку, при запросе вперед показать последнюю строку.</p></blockquote></div><p>Но ведь это не отвечает запросу.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-07-07T02:52:23Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126764#p126764</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126759#p126759" />
			<content type="html"><![CDATA[<p>Я с такими файлами не сталкивался. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-07-06T22:23:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126759#p126759</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126758#p126758" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, так не получается:<br /></p><div class="codebox"><pre><code>TestFile=1`r2`r3
FileDelete, TestFile.txt
FileAppend, %TestFile%, TestFile.txt
MsgBox, % FileReadLineFromEnd(&quot;TestFile.txt&quot;, 2)

FileReadLineFromEnd(filePath, nLineFromEnd)  {
   FileRead, text, % filePath
   arr := StrSplit(text, &quot;`n&quot;, &quot;`r&quot;)
   Return arr[ObjMaxIndex(arr) - nLineFromEnd + 1]
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-07-06T22:22:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126758#p126758</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Поиск последней строки в .txt]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=126757#p126757" />
			<content type="html"><![CDATA[<p>Или так:<br /></p><div class="codebox"><pre><code>filePath := &quot;D:\Downloads\test.txt&quot;
MsgBox, % FileReadLineFromEnd(filePath, 2)

FileReadLineFromEnd(filePath, nLineFromEnd)  {
   FileRead, text, % filePath
   arr := StrSplit(text, &quot;`n&quot;, &quot;`r&quot;)
   Return arr[ObjMaxIndex(arr) - nLineFromEnd + 1]
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-07-06T21:56:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=126757#p126757</id>
		</entry>
</feed>
