GetAttr giving unexpected results

  • Thread starter Thread starter Janelle
  • Start date Start date
J

Janelle

I have a code that creates a list of all the files and
subfolders in a directory. It's been working fine, but
all of a sudden, GetAttr of a file
("T:\Janelle\TestFolder\Original\79017499.xls") is giving
a result of 2080 instead of the expected result of no more
than 127. Has anybody ever seen this sort of thing
before? What's going on here?
 
I meant 2048 = compressed.

This is the full list of attribute code as far as I know. It doesn't look
as if VB help has been updated in a while.

--
Jim Rech
Excel MVP

FILE_ATTRIBUTE_READONLY 1
FILE_ATTRIBUTE_HIDDEN 2
FILE_ATTRIBUTE_SYSTEM 4
FILE_ATTRIBUTE_DIRECTORY 16
FILE_ATTRIBUTE_ARCHIVE 32
FILE_ATTRIBUTE_DEVICE 64
FILE_ATTRIBUTE_NORMAL 128
FILE_ATTRIBUTE_TEMPORARY 256
FILE_ATTRIBUTE_SPARSE_FILE 512
FILE_ATTRIBUTE_REPARSE_POINT 1024
FILE_ATTRIBUTE_COMPRESSED 2048
FILE_ATTRIBUTE_OFFLINE 4096
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 8192
FILE_ATTRIBUTE_ENCRYPTED 16384
 
Wow, thanks! That's certainly a lot more attributes than
either the help files or the Object Browser shows!
One question, though. The VBA VbFileAttribute class has a
constant called vbNormal = 0. How is that different from
the FILE_ATTRIBUTE_NORMAL = 128 that you listed?
 
How is that different from the FILE_ATTRIBUTE_NORMAL = 128 that you
listed?

They are the same. As far as I can tell the VB authors decided to convert
the 128 that the Windows API call returns (that the VB GetAttrib function
undoubtedly calls) from 128 to 0. You can run this to prove that. You may
find other differences for all I know.

Declare Function GetFileAttributes Lib "kernel32.dll" Alias
"GetFileAttributesA" ( _
ByVal lpFileName As String) As Long

Sub VBA()
MsgBox GetAttr("C:\FileWithNoAttributes.xls")
End Sub

Sub WindowsAPI()
MsgBox GetFileAttributes("C:\FileWithNoAttributes.xls")
End Sub
 
Back
Top