sshrum Posted November 11, 2011 Share Posted November 11, 2011 (edited) 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: expandcollapse popup#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 November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 (edited) A StringSplit returns - what surprise - strings So before you can use them in a numeric comparison opperation you have to change the strings to numbers. Changeif $aTimestamp[2] < 10 then $aTimestamp[2] = "0" & $aTimestamp[2]toif Number($aTimestamp[2]) < 10 then $aTimestamp[2] = "0" & Timestamp[2] Edited November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
trancexx Posted November 11, 2011 Share Posted November 11, 2011 (edited) You are changing input.In your first post you had 2 - 17 and in your last 2 - 017. Or that wasn't input?You have to make up your mind on what you have as input. Edited November 11, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) consolewrite(VarGetType($sTimestamp)) returns back String. Looping thru the array returns String for all entries (1-6...0=Int32). This is weird. Edited November 11, 2011 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 More sharing options...
trancexx Posted November 11, 2011 Share Posted November 11, 2011 Check how many characters every element of array have? maybe "17" is in fact "something17". ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 (edited) I tried your script on Windows 7 64bit and it doesn't return anything. So maybe there's a problem with function _GetExtProperty. Edited November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 (edited) 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)? expandcollapse popup#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 November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
trancexx Posted November 11, 2011 Share Posted November 11, 2011 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 More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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: 22Arraydisplay()0 - 61 - 62 - 173 - 20114 - 65 - 126 - PMString, 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 - 61 - 062 - 0173 - 20114 - 125 - 126 - PM Edited November 11, 2011 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 More sharing options...
water Posted November 11, 2011 Share Posted November 11, 2011 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
sshrum Posted November 11, 2011 Author Share Posted November 11, 2011 (edited) 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 November 11, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now