Jump to content

How to Get Created Date from File Properties with Autoit


Recommended Posts

Hi,

 

I tried what is saying here: https://www.autoitscript.com/forum/topic/148232-_filegetproperty-retrieves-the-properties-of-a-file/

to get File properties: Created Date, but i'm lost.

 

I would like to include this bit of code into another more complex, but for now, i would like to know: "How to Get Created Date from File Properties with Autoit".

Thank you.

Link to post
Share on other sites

Ok, so ...

 

I have a folder, where i gave a bunch of pngs. I want to get created date from those.

What should i modify from here: 

#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIError.au3>
#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

Example()

Func Example()
    Local $hFile, $tFile, $aTime
    Local $sTempFile = @TempDir & "\Test.xyz"

    ; Create GUI
    GUICreate("Time", 400, 300)
    $g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Create test file and set file times
    $hFile = _WinAPI_CreateFile($sTempFile, 1)
    If $hFile = 0 Then _WinAPI_ShowError("Unable to create file")
    $tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
    _Date_Time_SetFileTime($hFile, $tFile, $tFile, $tFile)
    _WinAPI_CloseHandle($hFile)

    ; Read file times
    $hFile = _WinAPI_CreateFile($sTempFile, 2)
    If $hFile = 0 Then _WinAPI_ShowError("Unable to open file")
    $aTime = _Date_Time_GetFileTime($hFile)
    _WinAPI_CloseHandle($hFile)

    MemoWrite("Created ..: " & _Date_Time_FileTimeToStr($aTime[0]))
    MemoWrite("Accessed .: " & _Date_Time_FileTimeToStr($aTime[1]))
    MemoWrite("Modified .: " & _Date_Time_FileTimeToStr($aTime[2]))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    FileDelete($sTempFile)
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

With what so i can get what i want?

Thank you.

Link to post
Share on other sites

Why are you making the script more complex than it needs to be?

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

Example()

Func Example()
    Const $sTempFile = @TempDir & "\Test.xyz"
    
    ; Create GUI
    GUICreate("Time", 400, 300)
    $g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Create temp file
    If Not FileWrite($sTempFile, "") Then Exit MsgBox($MB_ICONERROR+$MB_TOPMOST, "ERROR", "Unable to write temp file.")

    MemoWrite("Created ..: " & FileGetTime($sTempFile, $FT_CREATED , $FT_STRING))
    MemoWrite("Accessed .: " & FileGetTime($sTempFile, $FT_ACCESSED, $FT_STRING))
    MemoWrite("Modified .: " & FileGetTime($sTempFile, $FT_MODIFIED, $FT_STRING))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    FileDelete($sTempFile)
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

Edited by TheXman
Link to post
Share on other sites
4 hours ago, TheXman said:

Why are you making the script more complex than it needs to be?

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

Example()

Func Example()
    Const $sTempFile = @TempDir & "\Test.xyz"
    
    ; Create GUI
    GUICreate("Time", 400, 300)
    $g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)

    ; Create temp file
    If Not FileWrite($sTempFile, "") Then Exit MsgBox($MB_ICONERROR+$MB_TOPMOST, "ERROR", "Unable to write temp file.")

    MemoWrite("Created ..: " & FileGetTime($sTempFile, $FT_CREATED , $FT_STRING))
    MemoWrite("Accessed .: " & FileGetTime($sTempFile, $FT_ACCESSED, $FT_STRING))
    MemoWrite("Modified .: " & FileGetTime($sTempFile, $FT_MODIFIED, $FT_STRING))

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    FileDelete($sTempFile)
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

That was the example from the help file of docs/libfunctions/_Date_Time_GetFileTime.htm ..... I dind't write a thing :))

I just try to figure out how do i do to get the Created date of a file.

Link to post
Share on other sites
8 hours ago, BogdanNicolescu said:

Yes, i tried that already, give's me nothing.

Well I ran it across my desktop and it works fine, so please post what you tried, here is my desktop script:

#include <File.au3>

Global $g_aPNGList = _FileListToArrayRec(@DesktopDir, "*.png", 1, 1, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to create file list.")
Global $g_sPNGCreated
For $i = 1 To $g_aPNGList[0]
    $g_sPNGCreated = FileGetTime($g_aPNGList[$i], 1, 0)
    ConsoleWrite($g_aPNGList[$i] & " = Created DD/MM/YYYY HH:MM:SS : " & $g_sPNGCreated[2] & "/" & $g_sPNGCreated[1] & "/" & $g_sPNGCreated[0] & " " & $g_sPNGCreated[3] & ":" & $g_sPNGCreated[4] & ":" & $g_sPNGCreated[5] & @CRLF)
Next

 

Link to post
Share on other sites
4 hours ago, Subz said:

Well I ran it across my desktop and it works fine, so please post what you tried, here is my desktop script:

#include <File.au3>

Global $g_aPNGList = _FileListToArrayRec(@DesktopDir, "*.png", 1, 1, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to create file list.")
Global $g_sPNGCreated
For $i = 1 To $g_aPNGList[0]
    $g_sPNGCreated = FileGetTime($g_aPNGList[$i], 1, 0)
    ConsoleWrite($g_aPNGList[$i] & " = Created DD/MM/YYYY HH:MM:SS : " & $g_sPNGCreated[2] & "/" & $g_sPNGCreated[1] & "/" & $g_sPNGCreated[0] & " " & $g_sPNGCreated[3] & ":" & $g_sPNGCreated[4] & ":" & $g_sPNGCreated[5] & @CRLF)
Next

 

NOW! This is ENTIRE different thing then what i have read ...

Yes, it works .... but now ... how do i change the dir?

Thank you.

Link to post
Share on other sites
  • Developers
24 minutes ago, BogdanNicolescu said:

Yes, it works .... but now ... how do i change the dir?

What do you mean?  Run this script for another directory?
If that is really the question it is time you have a closer look at the script yourself and try to understand it as the answer is pretty obvious. ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
4 minutes ago, Jos said:

What do you mean?  Run this script for another directory?
If that is really the question it is time you have a closer look at the script yourself and try to understand it as the answer is pretty obvious. ;) 

Jos

I'm clueless ... can you throw me a hint?

I imagine it has to do somthing with this: 

@DesktopDir

 

But i don't see how, as my folder resides in another partition.

How do i change that to something like this: F:\++\Folder340\_+_\2020\07 2020\Folder890

Or, how do i make it found Folder890?

Thank you.

Link to post
Share on other sites
  • Developers
1 minute ago, BogdanNicolescu said:

How do i change that to something like this: F:\++\Folder340\_+_\2020\07 2020\Folder890

Come on....Did you try at all?  Maybe open the Helpfile (F1) so you can find that information? 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
3 minutes ago, Jos said:

Come on....Did you try at all?  Maybe open the Helpfile (F1) so you can find that information? 

Jos

Looked at that f1 thingy ... it spit me right back in my face 😄😄

I would much rather use something like this: 

FileSelectFolder ( "dialog text", "root dir" [, flag = 0 [, "initial dir" [, hwnd]]] )

if it's possible, but i don't know where to insert it.

Link to post
Share on other sites
  • Developers

So you spent about 1 minute to try and understand? 

Try harder and come back when you have something to show for.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
14 minutes ago, Jos said:

Show what you have tried and isn't working.... we are not going to do the work for you.

I treid all @ from that list, including (for the fun of it) @DesktopHeight, but now i tried something different, something that it dose not require "@" 

#include <File.au3>

Global $g_aPNGList = _FileListToArrayRec ("F:\++\Folder340\_+_\2020\07 2020\Folder890", "*.png", 1, 1, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to create file list.")
Global $g_sPNGCreated
For $i = 1 To $g_aPNGList[1]
    $g_sPNGCreated = FileGetTime($g_aPNGList[$i], 1, 0)
    ConsoleWrite($g_aPNGList[$i] & " = Created DD/MM/YYYY HH:MM:SS : " & $g_sPNGCreated[2] & "/" & $g_sPNGCreated[1] & "/" & $g_sPNGCreated[0] & " " & $g_sPNGCreated[3] & ":" & $g_sPNGCreated[4] & ":" & $g_sPNGCreated[5] & @CRLF)
Next

The problem is that it does not show me neither an error, or a result, just that it has finished nothing :))

Link to post
Share on other sites

Now, when i use this:

 

#include <File.au3>

Global $g_aPNGList = _FileListToArrayRec ("F:\++\Folder340\_+_\2020\07 2020\Folder890, "*.png"", 1, 1, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to create file list.")
Global $g_sPNGCreated
For $i = 1 To $g_aPNGList[1]
    $g_sPNGCreated = FileGetTime($g_aPNGList[$i], 1, 0)
    ConsoleWrite($g_aPNGList[$i] & " = Created DD/MM/YYYY HH:MM:SS : " & $g_sPNGCreated[2] & "/" & $g_sPNGCreated[1] & "/" & $g_sPNGCreated[0] & " " & $g_sPNGCreated[3] & ":" & $g_sPNGCreated[4] & ":" & $g_sPNGCreated[5] & @CRLF)
Next

It says that autoit has stopped working 😂

Edited by BogdanNicolescu
Link to post
Share on other sites

this is the corect answer:

#include <File.au3>

Global $g_aPNGList = _FileListToArrayRec("F:\++\Folder340\_+_\2020\07 2020\Folder890", "*.png", 1, 1, 0, 2)
If @error Then Exit MsgBox(4096, "Error", "Unable to create file list.")
Global $g_sPNGCreated
For $i = 1 To $g_aPNGList[0]
    $g_sPNGCreated = FileGetTime($g_aPNGList[$i], 1, 0)
    ConsoleWrite($g_aPNGList[$i] & " = Created DD/MM/YYYY HH:MM:SS : " & $g_sPNGCreated[2] & "/" & $g_sPNGCreated[1] & "/" & $g_sPNGCreated[0] & " " & $g_sPNGCreated[3] & ":" & $g_sPNGCreated[4] & ":" & $g_sPNGCreated[5] & @CRLF)
Next

Thank you all :)
 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...