<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Определить размер файла.]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16997&amp;type=atom" />
	<updated>2022-02-26T04:28:36Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16997</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152446#p152446" />
			<content type="html"><![CDATA[<p>Как итог решил задачу так:<br /></p><div class="codebox"><pre><code>SetBatchLines, -1

if A_Args.Length() &lt; 1 {
	MsgBox % &quot;Run:`nPATH\autohotkey.exe fileSize.ahk FILENAME&quot;
	ExitApp
}

file := A_Args[1]
pos := RegExMatch(file, &quot;^.:\\&quot;)

if (pos = 0)
	file := &quot;\\?\&quot; . A_WorkingDir . &quot;\&quot; . file
else
	file := &quot;\\?\&quot; . file

FileGetSize, OutputVar, %file%
MsgBox Size of %OutputVar% bytes.</code></pre></div><p>Осталось сделать вывод в консоль.</p>]]></content>
			<author>
				<name><![CDATA[DnsIs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26282</uri>
			</author>
			<updated>2022-02-26T04:28:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152446#p152446</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152442#p152442" />
			<content type="html"><![CDATA[<p><strong>DnsIs</strong>, но причём тут AHK?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-02-25T12:27:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152442#p152442</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152440#p152440" />
			<content type="html"><![CDATA[<p>Даже не включая поддержку длинных путей<br />Так работает</p><div class="codebox"><pre><code>dir \\?\c:\_test /s/a-d</code></pre></div><p>а так нет</p><div class="codebox"><pre><code>(@for /F &quot;delims=&quot; %a in (&#039;dir \\?\c:\_test /b/s/a-d&#039;) do @echo %~za %~fa)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[DnsIs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26282</uri>
			</author>
			<updated>2022-02-25T09:46:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152440#p152440</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152428#p152428" />
			<content type="html"><![CDATA[<p>Сам запутался и вас запутал.</p><p>Запускал на разных компьютерах, поэтому &quot;FileOpen&quot; на одном компе сработало, на другом нет.</p><p>Что говорит Гугл. Что бы включить в винде поддержку длинных имен, нужно явно включить в реестре:<br /></p><div class="codebox"><pre><code>[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
&quot;LongPathsEnabled&quot;=dword:00000001</code></pre></div><p>При таком раскладе, и Ваш Alectric и Ваш teadrinker примеры работают.</p><p>И тогда волшебным образом, команда <strong>dir </strong>заработает, но не всегда, если в наименовании файла встречается нестандартный символ (в моем случае длинное тире — (alt +&nbsp; 0 1 5 1)) то могут возникнуть трудности.<br />(в логе заменил длинный путь на <strong>LONG_PATH</strong> для простоты)<br /></p><div class="codebox"><pre><code>c:\_test&gt;dir /s/a-d
 Содержимое папки c:\LONG_PATH

24.02.2022  09:47                11 and_here_is_the_file_itself_with_a_long_name.txt
24.02.2022  09:47                12 and_here_is_the_file_itself_with_a_long_name—.txt
               2 файлов             23 байт

     Всего файлов:
               2 файлов             23 байт
               0 папок  16 050 933 760 байт свободно

c:\_test&gt;(@for /F &quot;delims=&quot; %a in (&#039;dir /b/s/a-d&#039;) do @echo %~za %~fa)
11 c:\LONG_PATH\and_here_is_the_file_itself_with_a_long_name.txt
 c:\LONG_PATH\and_here_is_the_file_itself_with_a_long_name-.txt</code></pre></div><p>А почему я заговорил про недокументированные функции WinApi?</p><p>Потому что, независимо от ключа реестра <strong>&quot;LongPathsEnabled&quot;=dword:00000001</strong>, включен он или выключен некоторым программам, наплевать на длинные пути, они работают, например Total Commander или:</p><div class="codebox"><pre><code>
c:\_test&gt;robocopy . nil /L /E /FP /BYTES /NDL /NJH /NJS

            Новый файл                11        c:\LONG_PATH\and_here_is_the_file_itself_with_a_long_name.txt
            Новый файл                12        c:\LONG_PATH\and_here_is_the_file_itself_with_a_long_name-.txt</code></pre></div><p>Та-дам!</p>]]></content>
			<author>
				<name><![CDATA[DnsIs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26282</uri>
			</author>
			<updated>2022-02-24T04:43:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152428#p152428</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152419#p152419" />
			<content type="html"><![CDATA[<p>А какая ОС?<br />На десятке работает такой код:<br /></p><div class="codebox"><pre><code>dir := &quot;c:\_test\First_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters\Second_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters&quot;

fileName := &quot;and_here_is_the_file_itself_with_a_long_name.txt&quot;

FileCreateDir, % dir
MsgBox, % &quot;FileCreateDir: &quot; . (ErrorLevel ? &quot;fail&quot; : &quot;success&quot;)

FileAppend, text, %dir%\%fileName%
MsgBox, % &quot;FileAppend: &quot; . (ErrorLevel ? &quot;fail&quot; : &quot;success&quot;)

FileGetSize, size, %dir%\%fileName%
MsgBox, % &quot;FileGetSize: &quot; . (ErrorLevel ? &quot;fail&quot; : &quot;success&quot;) . &quot;`nsize: &quot; . size

FileRemoveDir, c:\_test, 1
MsgBox, % &quot;FileRemoveDir: &quot; . (ErrorLevel ? &quot;fail&quot; : &quot;success&quot;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-02-22T11:27:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152419#p152419</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152418#p152418" />
			<content type="html"><![CDATA[<p><a href="https://www.autohotkey.com/docs/objects/File.htm">File Object</a><br /></p><div class="codebox"><pre><code>FileObj := FileOpen(a_scriptfullpath,&quot;r&quot;)
FileSize := FileObj.Length
FileObj.Close()
msgbox,% FileSize &quot; bytes&quot;
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-02-22T11:26:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152418#p152418</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Определить размер файла.]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=152417#p152417" />
			<content type="html"><![CDATA[<p>Доброго дня.</p><p>Моя конечная цель, просто получить размер файла с длинным путем (&gt; 260символов). Утилит, удовлетворяющих, не нашел (консольных) для встраивания в батник. Мне вроде бы и не нужен ahk (я с ним не дружу вообще), но он позволяет работать с WinAPI.<br /><strong>NtQueryInformationFile</strong> - кажись это оно, нашел пример работы:</p><div class="codebox"><pre><code>filepath := &quot;c:\_test\First_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters\Second_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters\and_here_is_the_file_itself_with_a_long_name.txt&quot;
File := FileOpen(filepath, &quot;r&quot;)
MsgBox % accessmode(File)
File.Close()

accessmode(File) {
	Local
	VarSetCapacity(ioStatus, 12, 0)
	er := DllCall(&quot;ntdll.dll\NtQueryInformationFile&quot;, &quot;Ptr&quot;, File.__handle, &quot;Ptr&quot;, &amp;ioStatus, &quot;UIntP&quot;, ACCESS_MASK:=0, &quot;Int&quot;, 4, &quot;Int&quot;, FileAccessInformation:=0x8)
	Return Format(&quot;{:}{:}&quot;, ACCESS_MASK &amp; 1 ? &quot;r&quot; : &quot;&quot;, ACCESS_MASK&gt;&gt;1 &amp; 1 ? &quot;w&quot; : &quot;&quot;)
}
</code></pre></div><p>Я правильно понимаю, функция FileOpen вполне себе открывает файл?</p><p>Нашел решение на C:</p><div class="codebox"><pre><code>status = NtQueryInformationFile(
	(void*)handle, 
	&amp;ioStatusBlock,
	&amp;openInfo, 
	sizeof(openInfo), 
	FileNetworkOpenInformation);
	
if (!NT_SUCCESS(status))
	return RtlNtStatusToDosError(status);
else
{
	if (filesize)
		*filesize = (unsigned int)openInfo.EndOfFile.u.LowPart;
	return STATUS_SUCCESS;
}</code></pre></div><p>Пробую так:</p><div class="codebox"><pre><code>filepath := &quot;c:\_test\First_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters\Second_level_directory_with_a_long_name_for_checking_paths_in_windows_with_a_limit_of_two_hundred_and_six_children_characters\and_here_is_the_file_itself_with_a_long_name.txt&quot;
File := FileOpen(filepath, &quot;r&quot;)
MsgBox % size(File)
File.Close()

size(File) {
	Local
	VarSetCapacity(ioStatus, 12, 0)
	er := DllCall(&quot;ntdll.dll\NtQueryInformationFile&quot;, &quot;Ptr&quot;, File.__handle, &quot;Ptr&quot;, &amp;ioStatus, &quot;UIntP&quot;, ACCESS_MASK:=0, &quot;Int&quot;, 4, &quot;Int&quot;, FileAccessInformation:=0x34)
	Return %ACCESS_MASK%
}</code></pre></div><p>По сути поменял только строку:<br />FileAccessInformation:=8<br />на<br />FileAccessInformation:=0x34</p><p>ЧЯДНТ?</p>]]></content>
			<author>
				<name><![CDATA[DnsIs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26282</uri>
			</author>
			<updated>2022-02-22T10:26:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=152417#p152417</id>
		</entry>
</feed>
