IsTime Function

I could do with some help getting the deatils I need as havent got a clue how to limit the list so I can get the date taken, size I already get that but might as well get them all from one place.


If you could point me in the right direction I might be able to get any other details I think of if icluded thanks mick


P.S. Did notice this
Code:
Do Until I = 0 'find the last "\" and get the filename
        I = InStr(1, strFileName, "\", vbBinaryCompare)
        strFileName = Mid(strFileName, I + 1)
    Loop
Can you not use InStrRev to get the last "\ " ?
 
Last edited:
Remember I supplied two links.
Here is the output for the same file with each app
1. Extended File Properties
attachment.php


2. Folder Image Viewer
attachment.php


You may find the image viewer sufficient for your needs
Have a look and get back to me if you still need help.

I often use InStrRev. There may be a reason why I didn't use it in that case. Will have a look later
 

Attachments

  • ExtendedFileProperties.PNG
    ExtendedFileProperties.PNG
    34.8 KB · Views: 317
  • FolderImageViewer.jpg
    FolderImageViewer.jpg
    81.2 KB · Views: 311
Thanks will look


mick
 
Looked at the folder images It uses FilesystemObject which I fully understand but wont give me the properties I need so came across this code


Code:
Private Sub fnFolderItem2ExtendedPropertyVB()

With CreateObject("Shell.Application").Namespace("C:\Kylie Minogue\Singles Covers")
        MsgBox .GetDetailsOf(.Items.Item("2014-09-08 18.16.11.jpg"), 5) & vbNewLine & _
         .Items.Item("2014-09-08 18.16.11.jpg").ExtendedProperty("Date modified") & vbNewLine & _
         .Items.Item("2014-09-08 18.16.11.jpg").ExtendedProperty("Type") & vbNewLine & _
         .Items.Item("2014-09-08 18.16.11.jpg").ExtendedProperty("Date Picture Taken") & vbNewLine & _
         .Items.Item("2014-09-08 18.16.11.jpg").ExtendedProperty("Author") & vbNewLine & _
         .Items.Item("2014-09-08 18.16.11.jpg").ExtendedProperty("Authors")
    End With
End Sub
which still wont gve me the properties I want lol but I learnt a bit more lol


https://docs.microsoft.com/en-us/pr...ve/ee176615(v=technet.10)?redirectedfrom=MSDN


I'll try a few other files just in case it's that file thanks mick
 
The thing about extended properties is that depending on who supplied the software used for your camera, phone, or other image-maker, not all extended properties are equally honored by all software vendors. The problem therefore is that some things will NEVER have a property of "Date Taken" simply because the vendor couldn't be bothered. In other cases, the problem will be that the date of that image can be programmed into the name, but you cannot rely on it always being yyyymmdd_hhnnss format. So ... not trying to be a wet blanket here, but you may have to take this project as an "if available" situation and be satisfied with what you can get.
 
The thing about extended properties is that depending on who supplied the software used for your camera, phone, or other image-maker, not all extended properties are equally honored by all software vendors. The problem therefore is that some things will NEVER have a property of "Date Taken" simply because the vendor couldn't be bothered. In other cases, the problem will be that the date of that image can be programmed into the name, but you cannot rely on it always being yyyymmdd_hhnnss format. So ... not trying to be a wet blanket here, but you may have to take this project as an "if available" situation and be satisfied with what you can get.


I hear you their the images I have been testing show a date/time taken in the default picture editor but trying to access the ones I want is driving me nuts but if I want to loop though all the properties theirs loads of code for that but running that against an import of say 600 images It would take forever.


I'm not ready to admit defeat yet I'll keep playing and learning maybe I'll get lucky lol
 
I've done some further checking and it is not possible to get DateTaken using FileSystemObject code. For a list of available properties using FSO, see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/file-object

To do that you need to extract the extended properties using the GetDetailsOf code. I agree with Doc that not all extended file properties are always available.
However where DateTaken is available it seems to be property ID = 12 for JPG files (though the PNG files I looked at don't seem to have that property)

Hope that helps
 
I have managed to get it like
Private Sub fnFolderItem2ExtendedPropertyVB()

With CreateObject("Shell.Application").Namespace("C:\Kylie Minogue\Singles Covers")
MsgBox .GetDetailsOf(.Items.Item("20140108_235915.jpg"), 12)
End With
End Sub


But It returns a funny format like ??08/?01/?2014 ??23:29 Which wouldn't be a problem as I could just use a replace for ? I'll keep testing with different files
 
That's doing exactly the same as my code.
I'm just getting all the extended properties rather than a selected value

This is from the GetExtFileProps procedure in modFileExtProps

Code:
 'get extended properties & values and save to table tblFileExtPropsTEMP
    For I = 0 To 310
        aName = objFolder.GetDetailsOf(objFolder.Items, I)
        aValue = objFolder.GetDetailsOf(objFolderItem, I)
       
       'full list of available extended properties (depending on file type)
    'Debug.Print I & " - " & objFolder.GetDetailsOf(objFolder.Items, I)
        
        'list extended properties available in this folder:
        If Nz(aName, "") <> "" And Nz(aValue, "") <> "" Then
            [B][COLOR="darkred"]Debug.Print I & " - " & aName & ": " & aValue[/COLOR][/B]
           
            'append query fails if any aName contains a '; replace with a |
            If InStr(aName, "'") > 0 Then
                aName = Replace(aName, "'", "|")
                N = N + 1
            End If
            
         [B][COLOR="darkred"]   'remove any '?' in extended property value
            aValue = Replace(aValue, "?", "")[/COLOR][/B]
        
            'append record to tblExtPropsFileType
            strSQL = "INSERT INTO tblFileExtPropsTEMP ( ID, ExtProperty, ExtPropValue )" & _
                " SELECT " & I & " AS ID, '" & aName & "' AS ExtProperty, '" & aValue & "' AS ExtPropValue ;"
                                
            CurrentDb.Execute strSQL
        End If
    Next I
    
    'now restore any ' replaced earlier with a |
    If N > 0 Then
        strSQL = "UPDATE tblFileExtPropsTEMP SET tblFileExtPropsTEMP.ExtProperty = Replace([ExtProperty],'|',''');"
        CurrentDb.Execute strSQL
    End If

Note the lines I've marked in RED BOLD type
The first prints the properties to the Immediate window
If you look at item 12, you will get the same result
e.g. 12 - Date taken: ?24/?05/?2017 ??19:25
Many other properties have '?' added as well

The second red bold line removes the extraneous ?
Further tidying was also needed to remove other unwanted characters
 
Cool


I did try a replace but wont work maybe i'm messing it up


Code:
Private Sub fnFolderItem2ExtendedPropertyVB()
Dim Str As String
With CreateObject("Shell.Application").Namespace("C:\Users\mickj\OneDrive\Pictures\Camera Roll")
        Str = .GetDetailsOf(.Items.Item("FB_IMG_13719896482005239.jpg"), 12)
    End With
        Str = Replace(Str, "?", "")
    Debug.Print Str
End Sub
 
That looks fine but it doesn't work for me either
Try using a modified version of my code instead
 
Borrowed your dimension code and made it into a function but found it a bit slow as it's got to open each image Does th unuesed funtion work for the dimension??


Code:
Private Function GetDimensions(strPath As String) As String
Dim objImage As Object
On Error GoTo Err_Handler

  
            Set objImage = CreateObject("WIA.ImageFile") 'use to get file dimensions
            objImage.LoadFile strPath
                GetDimensions = objImage.Width & " x " & objImage.Height
    Set objImage = Nothing

Exit_Handler:
   Exit Function

Err_Handler:
    If Err = 5 Or Err = 3163 Then Resume Next
    MsgBox "Error " & Err.Number & " in AddFileAttributes procedure: " & Err.Description, vbExclamation, "ERROR"
    Resume Exit_Handler

End Function


Do I need the error traps?? and I'm setting the obeject to nothing thing there was a small improvement in speed ??
 
If you look at the Wikipedia article, there is a section on structure that reveals a very interesting thing: The date that picture was taken isn't part of the image file. Which means that you get it only because whatever took the picture defined extended file attributes for you and put it in the file's metadata.

I found an article about .TIF and it doesn't contain the "Taken" date in the TIF Image File Header or Image File Directory. Therefore, again it would depend on whether your .TIF creator was nice and offered an extended attribute.

GIF and its corporate relative, PNG, don't have "date taken" embedded in the file either. So in summary, in every case I could find, the "Date Taken" is there if and only if the extended file attributes are set up to include that date/time.

I tried to find a list of all known extended file attributes but that is not quite so easy to find. I'm on my one-lung machine right now 'cause my preferred beast is still in shop, so it is hard for me to look up stuff like this. Searches are literally painfully slow on this old clunker. What IS clear that is that the list relates to optional things, not certainties. There is a "core" section of attributes. All the rest, a couple of hundred in number, are strictly optional based on the thing creating the file.
 
Borrowed your dimension code and made it into a function but found it a bit slow as it's got to open each image Does th unuesed funtion work for the dimension?

The reason the GetDimensions function isn't used is that I'm using the same code directly as a single line in the AddFileAttributes function
Code:
!Dimensions = objImage.Width & " x " & objImage.Height
You can use it separately if you wish but there will be no increase in speed

Setting objImage to nothing after each image only to reset it again on the next image is an unnecessary step that will slightly increase processing time. I would just clear it at the end

I've run this process on folders with over 1000 images and its taken less than 2 seconds even on my 8 year old slow PC.
 
Last edited:
If you look at the Wikipedia article, there is a section on structure that reveals a very interesting thing: The date that picture was taken isn't part of the image file. Which means that you get it only because whatever took the picture defined extended file attributes for you and put it in the file's metadata.

I found an article about .TIF and it doesn't contain the "Taken" date in the TIF Image File Header or Image File Directory. Therefore, again it would depend on whether your .TIF creator was nice and offered an extended attribute.

GIF and its corporate relative, PNG, don't have "date taken" embedded in the file either. So in summary, in every case I could find, the "Date Taken" is there if and only if the extended file attributes are set up to include that date/time.

I tried to find a list of all known extended file attributes but that is not quite so easy to find

Doc
You could have saved yourself a lot of time by downloading my Extended File Properties app mentioned earlier in this thread from sample databases or my website and testing a few files of each image type https://www.access-programmers.co.uk/forums/showthread.php?t=294548&highlight=Extended+file+properties

Here are some results for 6 common image types
attachment.php

From my tests, only JPG file type and its variants contain the DateTaken property. AFAIK these are used in all digital cameras.
 

Attachments

  • ImageTypeExtProperties.PNG
    ImageTypeExtProperties.PNG
    70.9 KB · Views: 276
The reason the GetDimensions function isn't used is that I'm using the same code directly as a single line in the AddFileAttributes function
Code:
!Dimensions = objImage.Width & " x " & objImage.Height
You can use it separately if you wish but there will be no increase in speed

I've run this process on folders with over 1000 images and its taken less than 2 seconds even on my 8 year old slow PC.


OK Thanks


Was going to see about reformating the date taken did you manage to get what you was working on working for it?
 
OK Thanks

Was going to see about reformating the date taken did you manage to get what you was working on working for it?

It works perfectly in my app. All ? marks were removed using the Replace function.
I didn't investigate why it failed for the almost identical code you downloaded from another source
 
I have about 130K Downloaded pictures that I collected over the last 20 years for the original picture Library, The jpg's all seem to still retain the date taken so it must be one of only properties not changed if the file is copied I will keep checking random images but think it will be worth the time to develope the date taken code for JPGs


mick
 
It works perfectly in my app. All ? marks were removed using the Replace function.
I didn't investigate why it failed for the almost identical code you downloaded from another source


After having my ariginal problem I copied your replace and used that but with my string variable I'll try it as a variant.


thanks for checking
 
I have about 130K Downloaded pictures that I collected over the last 20 years for the original picture Library, The jpg's all seem to still retain the date taken so it must be one of only properties not changed if the file is copied I will keep checking random images but think it will be worth the time to develope the date taken code for JPGs


mick

That's correct.
DateTaken is a property of the JPG file itself which is designed to be unchanged if the file is edited, renamed etc.
Though of course it is lost if you convert the file to png etc.
I don't follow your comment about developing the code for this.
The code to extract that from extended file properties already exists.
As already mentioned, you can't get it using file system object.
 

Users who are viewing this thread

Back
Top Bottom