Тема: AHK: Определить размер файла.
Доброго дня.
Моя конечная цель, просто получить размер файла с длинным путем (> 260символов). Утилит, удовлетворяющих, не нашел (консольных) для встраивания в батник. Мне вроде бы и не нужен ahk (я с ним не дружу вообще), но он позволяет работать с WinAPI.
NtQueryInformationFile - кажись это оно, нашел пример работы:
filepath := "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"
File := FileOpen(filepath, "r")
MsgBox % accessmode(File)
File.Close()
accessmode(File) {
Local
VarSetCapacity(ioStatus, 12, 0)
er := DllCall("ntdll.dll\NtQueryInformationFile", "Ptr", File.__handle, "Ptr", &ioStatus, "UIntP", ACCESS_MASK:=0, "Int", 4, "Int", FileAccessInformation:=0x8)
Return Format("{:}{:}", ACCESS_MASK & 1 ? "r" : "", ACCESS_MASK>>1 & 1 ? "w" : "")
}
Я правильно понимаю, функция FileOpen вполне себе открывает файл?
Нашел решение на C:
status = NtQueryInformationFile(
(void*)handle,
&ioStatusBlock,
&openInfo,
sizeof(openInfo),
FileNetworkOpenInformation);
if (!NT_SUCCESS(status))
return RtlNtStatusToDosError(status);
else
{
if (filesize)
*filesize = (unsigned int)openInfo.EndOfFile.u.LowPart;
return STATUS_SUCCESS;
}
Пробую так:
filepath := "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"
File := FileOpen(filepath, "r")
MsgBox % size(File)
File.Close()
size(File) {
Local
VarSetCapacity(ioStatus, 12, 0)
er := DllCall("ntdll.dll\NtQueryInformationFile", "Ptr", File.__handle, "Ptr", &ioStatus, "UIntP", ACCESS_MASK:=0, "Int", 4, "Int", FileAccessInformation:=0x34)
Return %ACCESS_MASK%
}
По сути поменял только строку:
FileAccessInformation:=8
на
FileAccessInformation:=0x34
ЧЯДНТ?