Jump to content

Weird reactions to EXIF returned data


sshrum
 Share

Recommended Posts

I'm making a file renamer for jpg files using someone elses EXIF extraction function.

Everything is going great except for when I try to do evals on the date.

I pick a photo file and I get back a string of '6/17/2011 6:12 PM' that I StringSplit with "/ :" so all the numbers get placed into an array like:

0 - 6

1 - 6

2 - 17

3 - 2011

4 - 6

5 - 12

6 - PM

Now when I do...

if $aTimestamp[2] < 10 then $aTimestamp[2] = "0" & $aTimestamp[2] ; Day

I should get back:

2 - 17

...but I'm not. Instead I get:

2 - 017

One thing to note, if I hard code in the $sTimestamp = "6/17/2011 6:12 PM", then it works fine. What data type is being returned here?

Here's the code:

#include <array.au3>
$path = FileOpenDialog("Select a file to read attributes",@ScriptDir,"All (*.*)")
$sTimestamp = _GetExtProperty($path,12)
;~ $sTimestamp = "6/17/2011 6:12 PM"
msgbox(0,"",$sTimestamp)
$aTimestamp = StringSplit($sTimestamp, "/ :")
_ArrayDisplay($atimestamp)
if $aTimestamp[1] < 10 then $aTimestamp[1] = "0" & $aTimestamp[1] ; Month
if $aTimestamp[2] < 10 then $aTimestamp[2] = "0" & $aTimestamp[2] ; Day
if StringUpper($aTimestamp[6]) = "PM" then
$aTimestamp[4] += 12 ; Hour + 12
Else
if $aTimestamp[4] < 10 then $aTimestamp[4] = "0" & $aTimestamp[4] ; Hour
EndIf
_ArrayDisplay($aTimestamp,"Property Array")

;===============================================================================
; Function Name: GetExtProperty($sPath,$iProp)
; Description: Returns an extended property of a given file.
; Parameter(s): $sPath - The path to the file you are attempting to retrieve an extended property from.
; $iProp - The numerical value for the property you want returned. If $iProp is is set
;  to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
;  The properties are as follows:
;  Name = 0
;  Size = 1
;  Type = 2
;  DateModified = 3
;  DateCreated = 4
;  DateAccessed = 5
;  Attributes = 6
;  Status = 7
;  Owner = 8
;  Author = 9
;  Title = 10
;  Subject = 11
;  Category = 12
;  Pages = 13
;  Comments = 14
;  Copyright = 15
;  Artist = 16
;  AlbumTitle = 17
;  Year = 18
;  TrackNumber = 19
;  Genre = 20
;  Duration = 21
;  BitRate = 22
;  Protected = 23
;  CameraModel = 24
;  DatePictureTaken = 25
;  Dimensions = 26
;  Width = 27
;  Height = 28
;  Company = 30
;  Description = 31
;  FileVersion = 32
;  ProductName = 33
;  ProductVersion = 34
; Requirement(s): File specified in $spath must exist.
; Return Value(s): On Success - The extended file property, or if $iProp = -1 then an array with all properties
; On Failure - 0, @Error - 1 (If file does not exist)
; Author(s): Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
$iExist = FileExists($sPath)
If $iExist = 0 Then
SetError(1)
Return 0
Else
$sFile = StringTrimLeft($sPath, StringInStr($sPath, "", 0, -1))
$sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "", 0, -1)))
$oShellApp = ObjCreate ("shell.application")
$oDir = $oShellApp.NameSpace ($sDir)
$oFile = $oDir.Parsename ($sFile)
If $iProp = -1 Then
Local $aProperty[35]
For $i = 0 To 34
$aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
Next
Return $aProperty
Else
$sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
If $sProperty = "" Then
Return 0
Else
Return $sProperty
EndIf
EndIf
EndIf
EndFunc ;==>_GetExtProperty
Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

A StringSplit returns - what surprise - strings :D

So before you can use them in a numeric comparison opperation you have to change the strings to numbers.

Change

if $aTimestamp[2] < 10 then $aTimestamp[2] = "0" &amp; $aTimestamp[2]
to
if Number($aTimestamp[2]) < 10 then $aTimestamp[2] = "0" & Timestamp[2]
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Number() doesn't work.

As I stated above...if I use a hardcoded string...the EXACT string...the evals work. It's really weird.

Here is the final array from the _GetExtProperty($path,12) after my evals:

0 - 6

1 - 06

2 - 017 <-- this should stay 17

3 - 2011

4 - 12 <-- this should have become 18

5 - 12

6 - PM

If I use my hardcoded $stimestamp = "6/17/2011 6:12 PM" string, this is the end array:

0 - 6

1 - 06

2 - 17

3 - 2011

4 - 18

5 - 12

6 - PM

So, as you can see, mathematical functions on strings do work...just not on the returned/split data I'm getting from _GetExtProperty($path,12)...hence my still unanswered question.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

You are changing input.

In your first post you had 2 - 17 and in your last 2 - 017.

You have to make up your mind on what you have as input.

Pre and post evals...my last post was the end results of the array. Nothing has changed. Everything stated above is correct.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Why should StringSplit add "0"? It doesn't.

This reproducer scripts uses function "Numbers" and works.

#include <array.au3>
$sTimestamp = "6/17/2011 6:12 PM"
$aTimestamp = StringSplit($sTimestamp, "/ :")
_ArrayDisplay($aTimestamp)
If Number($aTimestamp[1]) < 10 Then $aTimestamp[1] = "0" & $aTimestamp[1] ; Month
If Number($aTimestamp[2]) < 10 Then $aTimestamp[2] = "0" & $aTimestamp[2] ; Day
If StringUpper($aTimestamp[6]) = "PM" Then
    $aTimestamp[4] += 12 ; Hour + 12
Else
    If Number($aTimestamp[4]) < 10 Then $aTimestamp[4] = "0" & $aTimestamp[4] ; Hour
EndIf
_ArrayDisplay($aTimestamp, "Property Array")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Dewd...I KNOW!

As I pointed out 2 times now...the hardcoded entry works. Just as you hardcoded the entry. You can drop the Number() as well and it will still work.

For some reason the data returned from _GetExtProperty($path,12) is funky...I just don't know how. Any evals I do on the timestamp returned from _GetExtProperty($path,12) does not act normally.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Then try to loop through the array returned by _GetExtProperty($path,12) and write the data type to the console using VarGetType.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I tried your script on Windows 7 64bit and it doesn't return anything. So maybe there's a problem with function _GetExtProperty.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Use my code in the first post and point it at a JPG file...you should be able to repro the issue I'm seeing. I am also running Win7 64 bit. Other file types may not return timestamp info on 12.

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Unfortunately I get a different date/time format here in Austria so therefore I can't test.

Could you please run the modified version and check the MsgBox for correct result (type / length / content of data)?

#include <array.au3>
$path = FileOpenDialog("Select a file to read attributes", @ScriptDir, "All (*.*)")
$sTimestamp = _GetExtProperty($path, 12)
; $sTimestamp = "6/17/2011 6:12 PM"
MsgBox(0, "", ">" & $sTimestamp & "<" & @CRLF & "Length of string: " & StringLen($sTimestamp))
$aTimestamp = StringSplit($sTimestamp, "/ :")
_ArrayDisplay($aTimestamp)
For $i = 1 To $aTimestamp[0]
    MsgBox(0, "", VarGetType("Type: " & $aTimestamp[$i]) & ", Stringlen: " & StringLen($aTimestamp[$i]) & ", Data: >" & $aTimestamp[$i] & "<" & @CRLF)
Next
If $aTimestamp[1] < 10 Then $aTimestamp[1] = "0" & $aTimestamp[1] ; Month
If $aTimestamp[2] < 10 Then $aTimestamp[2] = "0" & $aTimestamp[2] ; Day
If StringUpper($aTimestamp[6]) = "PM" Then
    $aTimestamp[4] += 12 ; Hour + 12
Else
    If $aTimestamp[4] < 10 Then $aTimestamp[4] = "0" & $aTimestamp[4] ; Hour
EndIf
_ArrayDisplay($aTimestamp, "Property Array")

;===============================================================================
; Function Name: GetExtProperty($sPath,$iProp)
; Description: Returns an extended property of a given file.
; Parameter(s): $sPath - The path to the file you are attempting to retrieve an extended property from.
; $iProp - The numerical value for the property you want returned. If $iProp is is set
;  to -1 then all properties will be returned in a 1 dimensional array in their corresponding order.
;  The properties are as follows:
;  Name = 0
;  Size = 1
;  Type = 2
;  DateModified = 3
;  DateCreated = 4
;  DateAccessed = 5
;  Attributes = 6
;  Status = 7
;  Owner = 8
;  Author = 9
;  Title = 10
;  Subject = 11
;  Category = 12
;  Pages = 13
;  Comments = 14
;  Copyright = 15
;  Artist = 16
;  AlbumTitle = 17
;  Year = 18
;  TrackNumber = 19
;  Genre = 20
;  Duration = 21
;  BitRate = 22
;  Protected = 23
;  CameraModel = 24
;  DatePictureTaken = 25
;  Dimensions = 26
;  Width = 27
;  Height = 28
;  Company = 30
;  Description = 31
;  FileVersion = 32
;  ProductName = 33
;  ProductVersion = 34
; Requirement(s): File specified in $spath must exist.
; Return Value(s): On Success - The extended file property, or if $iProp = -1 then an array with all properties
; On Failure - 0, @Error - 1 (If file does not exist)
; Author(s): Simucal (Simucal@gmail.com)
; Note(s):
;
;===============================================================================
Func _GetExtProperty($sPath, $iProp)
    Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
    $iExist = FileExists($sPath)
    If $iExist = 0 Then
        SetError(1)
        Return 0
    Else
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "", 0, -1)))
        $oShellApp = ObjCreate("shell.application")
        $oDir = $oShellApp.NameSpace($sDir)
        $oFile = $oDir.Parsename($sFile)
        If $iProp = -1 Then
            Local $aProperty[35]
            For $i = 0 To 34
                $aProperty[$i] = $oDir.GetDetailsOf($oFile, $i)
            Next
            Return $aProperty
        Else
            $sProperty = $oDir.GetDetailsOf($oFile, $iProp)
            If $sProperty = "" Then
                Return 0
            Else
                Return $sProperty
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GetExtProperty
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I just tried a different jpg file and the evals worked! WTH????

JPG files from my smartphone work.

JPG files from my wife's samsung camera do not.

They both are returning valid timestamps, I just get f-ed up evals on all the ones from her Samsung data. Any ideas why that is happening?

I just posted the file I'm beating my head on. Here is a link to the Samsung file I'm using : http://www.shrum.net/SAM_0808.JPG

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

I just tried a different jpg file and the evals worked! WTH????

JPG files from my smartphone work.

JPG files from my wife's samsung camera do not.

They both are returning valid timestamps, I just get f-ed up evals on all the ones from her Samsung data. Any ideas why that is happening?

(it will just take you few posts up).

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I just edited...I posted the suspect JPG on my site (couldn't do as attachment here) and put a link to the file above. You should be able to save the picture to your system, and then run the script and point it at that file. See if you get the same results I'm seeing. Thanks.

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

I downloaded your JPG file and tried it with the script I Unfortunately the date returned is not the string you expect "6/17/2011 6:12 PM" but "17.06.2011 18:12".

This means the data in the JPG isn't a string but some kind of data which is interpreted and formatted by the operating system depending on the local data / time format.

I fear you have to run my edited version of the script yourself to get the correct output.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

OK...running your modified script I get back the following values on the photo I linked to (I've bolded the 'WTF' moments below):

>6/17/2011 6:12 PM<

Length of string: 22

Arraydisplay()

0 - 6

1 - 6

2 - 17

3 - 2011

4 - 6

5 - 12

6 - PM

String, Stringlen: 2, Data: >6<

String, Stringlen: 3, Data: >17<

String, Stringlen: 5, Data: >2011<

String, Stringlen: 3, Data: >6<

String, Stringlen: 2, Data: >12<

String, Stringlen: 2, Data: >PM<

Arraydisplay()

0 - 6

1 - 06

2 - 017

3 - 2011

4 - 12

5 - 12

6 - PM

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

You could use StringToASCIIArray to display the hex values of the string and check if there are any non-displayable characters.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Not sure what I'm looking at....here are the results of a StringtoASCIIArray:

[0] 8206

[1] 54

[2] 47

[3] 8206

[4] 49

[5] 55

[6] 47

[7] 8206

[8] 50

[9] 48

[10] 49

[11] 49

[12] 32

[13] 8207

[14] 8206

[15] 54

[16] 58

[17] 49

[18] 50

[19] 32

[20] 80

[21] 77

Edited by sshrum

Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...