How to get date created of document?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
milkygirl90
Posts: 44
Joined: 10 Nov 2020, 21:22

How to get date created of document?

18 Jan 2021, 19:57

Here's my script for inserting today's date. I regularly rename documents to start with the date created of the document itself in windows explorer. How do I "fetch" the date created and incorporate into my script?

Code: Select all

::-d::
FormatTime, CurrentDateTime,, yy-MM-dd
SendInput %CurrentDateTime%
Send {Space}
return
User avatar
milkygirl90
Posts: 44
Joined: 10 Nov 2020, 21:22

Re: How to get date created of document?

18 Jan 2021, 21:00

mikeyww wrote:
18 Jan 2021, 20:10
:arrow: FileGetTime
I did read the documentation, but not sure how I can get the file path directly while I'm in windows explorer with the file highlighted?

Code: Select all

FileGetTime, OutputVar, C:\My Documents\test.doc, C  ; Retrieves the creation time.
I'm stuck on this part:

Code: Select all

C:\My Documents\test.doc
User avatar
mikeyww
Posts: 5367
Joined: 09 Sep 2014, 18:38

Re: How to get date created of document?

18 Jan 2021, 21:45

Code: Select all

F3::
For itemNum, item in Explorer_GetSelection()
 FileGetTime, ctime, %item%, C
Clipboard =
FormatTime, Clipboard, %ctime%, yy-MM-dd
ClipWait
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
Else MsgBox,, Copied to clipboard, % Clipboard "`n`n(For " RegExReplace(item, ".+\\") ")"
Return

Explorer_GetSelection() {
 ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
 WinGetClass, winClass, % "ahk_id" hWnd := WinExist("A")
 If !(winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass")
  Return
 shellWindows := ComObjCreate("Shell.Application").Windows, sel := []
 If !(winClass ~= "Progman|WorkerW") {
  For window in shellWindows
   If (hWnd = window.HWND) && (shellFolderView := window.Document)
    Break
 } Else shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
 For item in shellFolderView.SelectedItems
  sel.Push(item.Path)
 Return sel
}
User avatar
milkygirl90
Posts: 44
Joined: 10 Nov 2020, 21:22

Re: How to get date created of document?

19 Jan 2021, 01:59

works beautifully, though the coding level is out of my league. thank you so much!
daywalker
Posts: 23
Joined: 18 Jun 2019, 01:37

Re: How to get date created of document?

19 Jan 2021, 02:51

Thanks mikeyww. On my system (Win10 x64) it shows the following error:
Explorer_GetSelection.png
Explorer_GetSelection.png (38.59 KiB) Viewed 115 times
The error source is window.HWND.
My workaround is to put a try statement before If (hWnd = window.HWND) && (shellFolderView := window.Document).
It works, but it is not beautiful. Do you know a better solution? Thank you!
User avatar
mikeyww
Posts: 5367
Joined: 09 Sep 2014, 18:38

Re: How to get date created of document?

19 Jan 2021, 05:57

It probably failed because you changed the function. In particular, you added a comma where there should not be one-- on the line before your error.

Would have a go with the original first, to see if that works.
daywalker
Posts: 23
Joined: 18 Jun 2019, 01:37

Re: How to get date created of document?

19 Jan 2021, 08:38

Problem now tracked, i have a shell window named javaw.exe which has no window handle (window.hwnd). Therefore the try command as workaround is helpful.
User avatar
mikeyww
Posts: 5367
Joined: 09 Sep 2014, 18:38

Re: How to get date created of document?

19 Jan 2021, 08:39

OK, good to know. Thank you for the update and solution.

Based on your information, a simple alternative could be to check for a null HWND and then act accordingly. Perhaps the following change could work (I did not test).

Code: Select all

If (window.HWND && hWnd = window.HWND && shellFolderView := window.Document)
gregster
Posts: 5837
Joined: 30 Sep 2013, 06:48

Re: How to get date created of document?

19 Jan 2021, 14:04

mikeyww wrote:
19 Jan 2021, 05:57
It probably failed because you changed the function. In particular, you added a comma where there should not be one-- on the line before your error.
Afaik, this is actually done by AHK internally at script start - and shouldn't be a problem.
You can check with ListLines.
User avatar
mikeyww
Posts: 5367
Joined: 09 Sep 2014, 18:38

Re: How to get date created of document?

19 Jan 2021, 14:11

It looks like you are right! Thank you, @gregster.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, genericindividual69, MatthewMirage, mikeyww, paul1965, roysubs and 53 guests