get list of files with dimensions (for image files)

narendra

Board Regular
Joined
Apr 15, 2008
Messages
95
Hello there,
I want to use a VBA code with which one can generate a list of files in a specified directory with file properties like size, attribute and date-time-stamps.

BUT MOST IMPORTANT thing is that I want to get the dimensions for image files
-OR-
Null /any defined value for non-image-files.

There some pretty good VBA codes using FileSystemObject which give most of these properties BUT, not the dimensions.

Can anybody tell me what code to use to get image dimensions.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello there,
I want to use a VBA code with which one can generate a list of files in a specified directory with file properties like size, attribute and date-time-stamps.

BUT MOST IMPORTANT thing is that I want to get the dimensions for image files
-OR-
Null /any defined value for non-image-files.

There some pretty good VBA codes using FileSystemObject which give most of these properties BUT, not the dimensions.

Can anybody tell me what code to use to get image dimensions.

One way to get info of this sought + extra is via Shell

you will need to parse the string data your self to get it into the cells etc

HTH

Ivan

Code:
Option Explicit
'/////////////////////////////////////////////////////////////////////////////
'// Description:
'// Retrieve Information Tip for a File as Displayed in Explorer view XP
'//
'// Requires:
'// DLL version shell32.dll version 4.71 or later
'// Operating systems:
'// Win2000, WinNT 4.0 with Internet Explorer*4.0, Win98, Win95 with Internet Explorer*4.0
'// Date: 29th June 2003
'//     Tested: WinXP / Excel2000
'//     By Ivan F Moala: http//www.XcelFiles.com
'//     Amend 12th April 2004
'//     Tested: WinXp / Excel2003
'//
'/////////////////////////////////////////////////////////////////////////////
Dim strShtName As String
Dim objFolder As Object
Dim strFullPath As String
Dim blnCreateLink As Boolean
Dim blnStatus As Boolean
Dim objShell As Object

'ParseName Method
'--------------------------------------------------------------------------------
'Creates and returns a FolderItem object that represents a specified item.
'
'Syntax
'
'ppid = Folder.ParseName(bName)
'Parameters
'
'bName Required. A string that specifies the name of the item.

'Return Value
'An object reference to the FolderItem object.

'Remarks
'ParseName should not be used for virtual folders such as My Documents.

Sub GetFileDetails()
Dim objShell  As Object
Dim objFolder As Object
Dim objFolderItem As Object
Dim strFilename As String
Dim strCap As String, strMsg As String
'// Must be a variant
Dim vDirNameSpace As Variant

'// Get File name
strFilename = Application.GetOpenFilename
If strFilename = "False" Then Exit Sub

'// Build details now
On Error GoTo ErrF
10 vDirNameSpace = FilePathOnly(strFilename)
20 strFilename = FileNameOnly(strFilename)
On Error GoTo 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(vDirNameSpace)

If (Not objFolder Is Nothing) Then
    Set objFolderItem = objFolder.ParseName(strFilename)
    If (Not objFolderItem Is Nothing) Then
        strCap = "Info on: " & strFilename
        strMsg = "Dir:=" & vDirNameSpace & vbCrLf
        MsgBox strMsg & objFolder.GetDetailsOf(objFolderItem, -1), vbInformation, strCap
    End If
    Set objFolderItem = Nothing
End If

Set objFolder = Nothing
Set objShell = Nothing

Exit Sub
ErrF:
MsgBox Err.Number & ":" & Err.Description & " @ Line " & Erl, vbCritical
End Sub

Function FileNameOnly(strFile As String) As String
Dim MyFile As String
Dim ArrName As Variant

#If VBA6 Then
    '// Xl2000+ Reverse the string
    MyFile = StrReverse(strFile)
    '// Get the string to the left of the first \ and reverse it
    MyFile = StrReverse(Left(MyFile, InStr(MyFile, "\") - 1))
    FileNameOnly = MyFile
#Else
    '// Xl97 Tom Ogilvy
    ArrName = Evaluate("{""" & Application.Substitute( _
            strFile, "\", """,""") & """}")
    FileNameOnly = ArrName(UBound(ArrName))
#End If

End Function

Function FilePathOnly(FullFileName As String) As String
    '// Use of favorites returns file only
    On Error Resume Next
    FilePathOnly = Left(FullFileName, Len(FullFileName) - Len(Dir(FullFileName, vbHidden + vbSystem)) - 1)
End Function
 
Upvote 0
Perfect one....I am looking for the same thing...One question....

Is it possible to have a list of "images in folder" along with their "attributes" like name, size, dimension in a csv file or excel file?

Thanks.



One way to get info of this sought + extra is via Shell

you will need to parse the string data your self to get it into the cells etc

HTH

Ivan

Code:
Option Explicit
'/////////////////////////////////////////////////////////////////////////////
'// Description:
'// Retrieve Information Tip for a File as Displayed in Explorer view XP
'//
'// Requires:
'// DLL version shell32.dll version 4.71 or later
'// Operating systems:
'// Win2000, WinNT 4.0 with Internet Explorer*4.0, Win98, Win95 with Internet Explorer*4.0
'// Date: 29th June 2003
'//     Tested: WinXP / Excel2000
'//     By Ivan F Moala: http//www.XcelFiles.com
'//     Amend 12th April 2004
'//     Tested: WinXp / Excel2003
'//
'/////////////////////////////////////////////////////////////////////////////
Dim strShtName As String
Dim objFolder As Object
Dim strFullPath As String
Dim blnCreateLink As Boolean
Dim blnStatus As Boolean
Dim objShell As Object

'ParseName Method
'--------------------------------------------------------------------------------
'Creates and returns a FolderItem object that represents a specified item.
'
'Syntax
'
'ppid = Folder.ParseName(bName)
'Parameters
'
'bName Required. A string that specifies the name of the item.

'Return Value
'An object reference to the FolderItem object.

'Remarks
'ParseName should not be used for virtual folders such as My Documents.

Sub GetFileDetails()
Dim objShell  As Object
Dim objFolder As Object
Dim objFolderItem As Object
Dim strFilename As String
Dim strCap As String, strMsg As String
'// Must be a variant
Dim vDirNameSpace As Variant

'// Get File name
strFilename = Application.GetOpenFilename
If strFilename = "False" Then Exit Sub

'// Build details now
On Error GoTo ErrF
10 vDirNameSpace = FilePathOnly(strFilename)
20 strFilename = FileNameOnly(strFilename)
On Error GoTo 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(vDirNameSpace)

If (Not objFolder Is Nothing) Then
    Set objFolderItem = objFolder.ParseName(strFilename)
    If (Not objFolderItem Is Nothing) Then
        strCap = "Info on: " & strFilename
        strMsg = "Dir:=" & vDirNameSpace & vbCrLf
        MsgBox strMsg & objFolder.GetDetailsOf(objFolderItem, -1), vbInformation, strCap
    End If
    Set objFolderItem = Nothing
End If

Set objFolder = Nothing
Set objShell = Nothing

Exit Sub
ErrF:
MsgBox Err.Number & ":" & Err.Description & " @ Line " & Erl, vbCritical
End Sub

Function FileNameOnly(strFile As String) As String
Dim MyFile As String
Dim ArrName As Variant

#If VBA6 Then
    '// Xl2000+ Reverse the string
    MyFile = StrReverse(strFile)
    '// Get the string to the left of the first \ and reverse it
    MyFile = StrReverse(Left(MyFile, InStr(MyFile, "\") - 1))
    FileNameOnly = MyFile
#Else
    '// Xl97 Tom Ogilvy
    ArrName = Evaluate("{""" & Application.Substitute( _
            strFile, "\", """,""") & """}")
    FileNameOnly = ArrName(UBound(ArrName))
#End If

End Function

Function FilePathOnly(FullFileName As String) As String
    '// Use of favorites returns file only
    On Error Resume Next
    FilePathOnly = Left(FullFileName, Len(FullFileName) - Len(Dir(FullFileName, vbHidden + vbSystem)) - 1)
End Function
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,381
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top