Listing of File Properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

How can I retrieve a listing of the various properties associated with a
file. I am using VBA to import a large quantity of image (well there paths
that is) into a db. I need to retrieve information about these images such
as filesize, width, height, resolution, ... (all of which are listed when you
access the file property summary) and add them into their respective fields
in the db?

Thank you.

Daniel
 
Check out FileSystemObject in VBA Help files. It has methods and properties
to provide you with the info that you seek for a file.
 
I found the following code online

****
Dim arrHeaders(34)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")
For i = 0 to 33
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
For i = 0 to 33
Wscript.echo i & vbtab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
Next
****

i then tried to mod it to use it as a function

****
Function FileDetails(strFilewFullPath As String)
Dim strFile As String
Dim strPath As String
Dim arrHeaders(34)
Dim i As Integer

strFile = Dir(strFilewFullPath)
strPath = Left(strFilewFullPath, Len(strFilewFullPath) - Len(strFile) - 1)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strPath)

For i = 0 To 33
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next

For Each strFileName In objFolder.Items
If strFileName = strFile Then
For i = 0 To 33
Output = Output & i & vbCrLf & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
End If
Next
MsgBox Output
End Function
****
The issue is specifically with the 'Set objFolder =
objShell.Namespace(strPath)' line. It seem to have an issue with my
variabel?! If I insert the path manually in the code ie: "c:\images" it
works fine. However, if I used the function and call it
FileDetails("c:\images\imgae01.jpg") I get an error 91? What am I doing
wrong?

Thank you,

Daniel
 
I don't quite understand the why of the matter but the solution was to change

Set objFolder = objShell.Namespace(strPath)

to

Set objFolder = objShell.Namespace(strPath & "\")

yet it was not required when hardcoded?

Daniel
 
Ken

Thank you for the links, I was having a hard time to locate useful links.
google bombared me with websites but most of them were not what I was looking
for. So much out there on the web, it just the case of being able to find it!

Thank you for all your help,

Daniel
 
Ken

Although the FileSystemObject does give me access to such information as
size, name, created and modified, I have been unable to find out if and how I
can use it to retrieve image related properties such as width height. Am I
missing something very obvious?

Could you also demonstrate one thing for me. In the case of the file Object
how can a programmer determine all of the properties available for that given
object. Is there a simple loop that can list all of them programmatically?

Thank you once again for your time (and patience),

Daniel
 
I was searching through Google Groups and cam across this:

****
This is called "OLE Structured Storage" and AFAIK is only supported at a
"higher-level" (defined structure) by M$ Office APIs for their own files.
For your own files you either have to steal one of the Office products
'structures' or write your own using the OLE container and compound file
APIs.

These APIs are easier to work with with C++. There is likely a VB solution
out there but I am not aware of one.
****

The author of this refered to 'extended file properties'? When I use the
properties they show up under the summary tab?

Anyways, does that mean anything to anyone (because I don't even understand
the terms that were used)? Does anyone have such an API?

Thank you,

Daniel
 
I do not know of a way to iterate through the list of properties/methods
available to a specific object within a FileSystemObject, sorry. So far as I
know, you must know the method/property in advance and call it by its
"name".

I have no experience with API overall. Stephen Lebans, MS ACCESS MVP, has
done a lot of special programming with API calls for his various solutions
to ACCESS issues... you might find some code in his examples at
www.lebans.com. I know that he has examples there for image files'
manipulations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top