Solved

How can I find the date property of jpg files?

Posted on 2013-01-31
3
410 Views
Last Modified: 2013-01-31
Hello

I'd like to write a routine in VBA for Excel that will iterate through all the jpg files in that folder and rename them to the following format: yymmdd followed by a four digit consecutive number (0001, 0002 etc) for all photos taken on the same date.

Using the GetFile method only allows me to find the Date Created or Date Modified properties, but because the files have been copied and possibly rotated (modified) these will not always give me the date I want, which is the standard Date as viewed in Windows Explorer detailed view.

How can I find this property using VBA?

Thanks,

Chris
0
Comment
Question by:thechrisrobertstoo
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 38839325
Sample function
Function GetFileInfo(sFilePath, n)
    Dim oFolder As Object
    Dim oFolderItem As Object
    Dim sPath
    Dim sFile
    Dim lPos As Long
    
    lPos = InStrRev(sFilePath, "\")
    sPath = left(sFilePath, lPos)
    sFile = Mid(sFilePath, lPos + 1)
    Set oFolder = CreateObject("Shell.Application").Namespace(sPath)
    Set oFolderItem = oFolder.ParseName(sFile)
    If Not oFolderItem Is Nothing Then GetFileInfo = oFolder.GetDetailsOf(oFolderItem, n)
End Function

Open in new window


called for example:
Sub Testit()
    Dim n As Long
    For n = 1 To 50
        Debug.Print "n = " & n & "; " & GetFileInfo("C:\Test\backgroundDefault.jpg", n)
    Next n
End Sub

Open in new window


the date taken used to be item 25 but seems to be 12 on my Win7 system.
0
 

Author Comment

by:thechrisrobertstoo
ID: 38839372
Thanks rorya

Any idea why item 12 show the dates with question marks, eg "?01/?01/?2013 ??16:15", which the items 3 to 5 don't?

Chris
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38839525
In all honesty, no - I'd just use Replace to get rid of them
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Recurring Excel Timelime for Veeam 2 37
Excel 3 24
Macro to delete column 3 11
Excel Worksheet Function of VBA Code 5 19
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now