I think you are looking for file properties, rather than attributes. Use
GetAttr() to get file attributes (readonly, archived, hidden, etc).
The code below reads file properties (name, type, date created, modified,
accessed, etc). This should be what you are looking for.
The original link (referenced below) was for reading jpg files, but if I
understand correctly, all files have the same number of properties, it's just
a matter of whether they have information in them.
The function FileGetProperties returns an array of all the properties (a
string, ex "Name: somefile.jpg". See the TestProps function for an idea how
to implement. This particular examples pulls returns the 3rd element of a
Base 0 array. You may need to loop the array until you get the required
element.
I have in mind to further break this down and enumerate the possible
properties so a function may return only the specified rather than all
properties, but I need to test this on various filetypes to see what property
names etc change and which are constant (if any) between files.
In the meantime, though, this seems to work well.
Public Function TestProps() As String
Dim ret As Variant
ret = FileGetProperties("D:\something.jpg")
TestProps = ret(2)
End Function
'==============================================================================
' FileGetProperties
'
' Adapted (copied) from Michael Pierron
'
http://www.pcreview.co.uk/forums/thread-1862574.php
'-----------------------
Public Function FileGetProperties(sfile As String) As Variant
On Error GoTo Err_Proc
Dim ret(34) As String
'==================
Dim i As Integer
Dim T As String
'==================
With CreateObject("Shell.Application").Namespace(Left( _
sfile, lPosition(sfile, "\") - 1))
For i = 0 To 34
T = .GetDetailsOf(.parsename(Dir(sfile)), i)
If Len(T) Then
ret(i) = .GetDetailsOf(.Items, i) & ":" & T
Debug.Print ret(i)
End If
Next i
End With
'==================
Exit_Proc:
FileGetProperties = ret
Exit Function
Err_Proc:
If cSYSDISPERR Then MsgBox "Error!" & vbCrLf & _
Str(Err.Number) & ": " & Err.Description, _
vbCritical, "Library Error!"
Resume Exit_Proc
Resume
End Function
Private Function lPosition%(Chain$, Char$)
'Dependant of FileGetProperties
Dim iPos%
Do
iPos = InStr(lPosition + 1, Chain, Char, 1)
If iPos Then lPosition = iPos Else Exit Do
Loop
End Function
--
Jack Leach
www.tristatemachine.com
"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)