FileGetAttrib

Propose new features and changes
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

FileGetAttrib

31 Oct 2023, 18:53

With the expanding use of OneDrive, I wonder if it might be useful to add the four starred file attribute constants in the script below to the FileGetAttrib function.

Code: Select all

#Requires AutoHotkey v2.0

MsgBox GetFileAttributesString(GetFileAttributes(A_ScriptFullPath))

; https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants

GetFileAttributesString(FileAttributes) {
   static INVALID_FILE_ATTRIBUTES := 0xFFFFFFFF
   static FILE_ATTRIBUTES := Map(0x00000001, 'R'   ; FILE_ATTRIBUTE_READONLY
                               , 0x00000002, 'H'   ; FILE_ATTRIBUTE_HIDDEN
                               , 0x00000004, 'S'   ; FILE_ATTRIBUTE_SYSTEM
                               , 0x00000010, 'D'   ; FILE_ATTRIBUTE_DIRECTORY
                               , 0x00000020, 'A'   ; FILE_ATTRIBUTE_ARCHIVE
                               , 0x00000080, 'N'   ; FILE_ATTRIBUTE_NORMAL
                               , 0x00000100, 'T'   ; FILE_ATTRIBUTE_TEMPORARY
                               , 0x00000400, 'L'   ; FILE_ATTRIBUTE_REPARSE_POINT
                               , 0x00000800, 'C'   ; FILE_ATTRIBUTE_COMPRESSED
                               , 0x00001000, 'O'   ; FILE_ATTRIBUTE_OFFLINE
                               , 0x00040000, 'E'   ; FILE_ATTRIBUTE_RECALL_ON_OPEN *
                               , 0x00080000, 'P'   ; FILE_ATTRIBUTE_PINNED *
                               , 0x00100000, 'U'   ; FILE_ATTRIBUTE_UNPINNED *
                               , 0x00400000, 'V')  ; FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS *
   
   if FileAttributes != INVALID_FILE_ATTRIBUTES {
      String := ''
      for FileAttribute, Char in FILE_ATTRIBUTES
         if FileAttributes & FileAttribute
            String .= Char, FileAttributes &= ~FileAttribute
      return (String ? String : 'X') (FileAttributes ? ' +' Format('0x{:08X}', FileAttributes) : '')
   }
}

GetFileAttributes(FileName) => DllCall('Kernel32.dll\GetFileAttributesW', 'WStr', FileName, 'UInt')
Previous version
Last edited by iPhilip on 17 Nov 2023, 23:04, edited 1 time in total.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: FileGetAttrib

16 Nov 2023, 20:28

X is reserved by FileExist to mean that the file exists but has no attributes.
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

Re: FileGetAttrib

17 Nov 2023, 23:04

@lexikos Thank you. I missed that. I modified the original post to reflect that condition.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 60 guests