Solved

How can I find the date property of jpg files?

Posted on 2013-01-31
3
418 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

930 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

11 Experts available now in Live!

Get 1:1 Help Now