Sign in to follow this  
Followers 0
guinness

[SOLVED] Date from a WMI Function is returning with ?? contained in the String.

4 posts in this topic

#1 ·  Posted (edited)

I'm using a Function by to get the Date/Time taken of a Photo.

What I can't get my head around is the Date returned contains ??'s when shown in the Console of SciTE, but in a MsgBox() this isn't the case.

My intention is to convert the date from 26/02/2011 15:15 to 26-02-2011, which as you can see in _Example_2() is working, so it isn't the SRE that's the problem. I have substituted ?? in the SRE (no use!) Tried StringReplace(), String() but to no avail. If anyone has an idea or a reference to MSDN then this would be much appreciated. :) Thank you.

The example below takes you through the steps:

Global $File = FileOpenDialog("Select A Photo", @ScriptDir, "(*.*)")
If @error Then Exit

_Example_1($File)
_Example_2($File)

Func _Example_1($sFilePath) ; Not Working!
    ConsoleWrite("Example 1 (Using Real Date!)" & @CRLF)
    $iDate = _Read_File_Properties($sFilePath) ; Get Files "Taken Date"
    ConsoleWrite("The Date of " & $sFilePath & " = " & $iDate & @CRLF)
    MsgBox(0, "Lets Check!", "Does the Console show ??'s in the date, because MsgBox() doesn't " & @CRLF & @CRLF & $iDate)
    $iConvertedDate = StringRegExpReplace($iDate, "(\d{2})/(\d{2})/(\d{4})\s+(\d{2}):(\d{2})", "$2-$1-$3") ; Convert 26/02/2011 15:15 >> 02-26-2011
    ConsoleWrite("The Date of " & $sFilePath & " converted from >> " & $iDate & " is " & $iConvertedDate & @CRLF & @CRLF)
EndFunc   ;==>_Example_1

Func _Example_2($sFilePath) ; Working!
    ConsoleWrite("Example 2 (Using Fake Date!)" & @CRLF)
    $iDate = "26/02/2011 15:15" ; Get Files "Taken Date"
    ConsoleWrite("The Date of " & $sFilePath & " = " & $iDate & @CRLF)
    MsgBox(0, "Lets Check!", "Does the Console show ??'s in the date, because MsgBox() doesn't " & @CRLF & @CRLF & $iDate)
    $iConvertedDate = StringRegExpReplace($iDate, "(\d{2})/(\d{2})/(\d{4})\s+(\d{2}):(\d{2})", "$2-$1-$3") ; Convert 26/02/2011 15:15 >> 02-26-2011
    ConsoleWrite("The Date of " & $sFilePath & " converted from >> " & $iDate & " is " & $iConvertedDate & @CRLF & @CRLF)
EndFunc   ;==>_Example_2

Func _Read_File_Properties($sPassed_File_Name) ; By Melba23: http://www.autoitscript.com/forum/topic/109450-file-properties/page__view__findpost__p__770326
    Local $iError = 0
    Local $sDir_Name = StringRegExpReplace($sPassed_File_Name, "(^.*\\)(.*)", "\1")
    Local $sFile_Name = StringRegExpReplace($sPassed_File_Name, "^.*\\", "")
    Local $sDOS_Dir = FileGetShortName($sDir_Name, 1)

    Local $oShellApp = ObjCreate("shell.application")
    If IsObj($oShellApp) Then
        Local $oDir = $oShellApp.NameSpace($sDOS_Dir)
        If IsObj($oDir) Then
            Local $oFile = $oDir.Parsename($sFile_Name)
            If IsObj($oFile) Then
                $sFile_Property = $oDir.GetDetailsOf($oFile, 12) ; Insert number for property required - Windows Vista/7: Time Taken Or Windows XP: 26
                Return $sFile_Property
            Else
                $iError = 3
            EndIf
        Else
            $iError = 2
        EndIf
    Else
        $iError = 1
    EndIf
    If $iError > 0 Then
        Local $sMsg = "Could not read File Properties" & @CRLF & @CRLF & _
                $iError & @CRLF & @CRLF & $sPassed_File_Name
        MsgBox(0, "Error", $sMsg)
    EndIf
EndFunc   ;==>_Read_File_Properties

UPDATED: See working code >>

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites



Hi,

no problem for me. Output shows :

Example 1 (Using Real Date!)
The Date of c:\Dokumente und Einstellungen\xf01145\Eigene Dateien\Eigene Bilder\Flyer\Dreh_CIMG6129_ohneRot.jpg = 07.02.2005 11:20
The Date of c:\Dokumente und Einstellungen\xf01145\Eigene Dateien\Eigene Bilder\Flyer\Dreh_CIMG6129_ohneRot.jpg converted from >> 07.02.2005 11:20 is 07.02.2005 11:20

Example 2 (Using Fake Date!)
The Date of c:\Dokumente und Einstellungen\xf01145\Eigene Dateien\Eigene Bilder\Flyer\Dreh_CIMG6129_ohneRot.jpg = 26/02/2011 15:15
The Date of c:\Dokumente und Einstellungen\xf01145\Eigene Dateien\Eigene Bilder\Flyer\Dreh_CIMG6129_ohneRot.jpg converted from >> 26/02/2011 15:15 is 02-26-2011

Besides I used

$sFile_Property = $oDir.GetDetailsOf($oFile, 25) ; Insert number for property required - Windows Vista/7: Time Taken Or Windows XP: 26

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks for Testing! :) You must be using XP because 25 is Blank on Vista/7. I forgot to mention that this is only Date out of all the properties that Returns one with ??

I think it's just one of those things on Vista/7!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

OK, so a kind user pointed me in the right direction, by using the following SRE destroyed the ??'s! :)

$iDate = StringRegExpReplace($iDate, "[^0-9]", "") ; Remove All Non-Digit Characters.

Example:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $File = FileOpenDialog("Select A Photo", @ScriptDir, "(*.*)")
If @error Then Exit
MsgBox(0, "_ImageTakenDate()", "The Image was taken on >> " & _ImageTakenDate($File))

Func _ImageTakenDate($hFileName) ; Modified From Code By Melba23: http://www.autoitscript.com/forum/topic/...operties/page__view__findpost_
    Local $iEntry = 12
    If @OSVersion = "WIN_XP" Then $iEntry = 26
    Local $sDirectoryName = StringRegExpReplace($hFileName, "(^.*\\)(.*)", "\1")
    Local $sFileName = StringRegExpReplace($hFileName, "^.*\\", "")
    Local $sDirectoryDOS = FileGetShortName($sDirectoryName, 1)

    Local $oObjCreate = ObjCreate("shell.application")
    If IsObj($oObjCreate) Then
        Local $oDirectory = $oObjCreate.NameSpace($sDirectoryDOS)
        If IsObj($oDirectory) Then
            Local $oFile = $oDirectory.Parsename($sFileName)
            If IsObj($oFile) Then Return _ConvertDate($oDirectory.GetDetailsOf($oFile, $iEntry))
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc   ;==>_ImageTakenDate

Func _ConvertDate($iDate)
    If Not StringInStr($iDate, ":") Then Return SetError(1, 0, 0)
    $iDate = StringRegExpReplace($iDate, "[^0-9]", "") ; Remove All Non-Digit Characters.
    Return StringRegExpReplace($iDate, "(\d{2})(\d{2})(\d{4})(\d{2})(\d{2})", "$1-$2-$3 $4:$5") ; Convert To 16-02-2011.
EndFunc   ;==>_ConvertDate
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
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
Sign in to follow this  
Followers 0