ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: AHK script to insert date and time to file name

<< < (4/4)

IainB:
@4wd: Thanks for the AutoIT code.
I just did pretty much the same thing in AHK out of interest (a training exercise) and for @metaDCoder (if needed):

Notes:

* This works for files and folders alike.


* I did this for xplorer² only, as that is the file explorer I use and I am unsure what the Active Window name for Windows Explorer is (or should be). You need a check like this so as to ensure that the code only runs when your file explorer is the active window, so that way it does not try to run when no file has been selected in a window for some other non-file explorer application.
I did this generically for Windows File Explorer otherwise. If I was doing this for myself, I might have some slightly different code as xplorer² has a command to pass the file name/path directly to the clipboard


* If you want to test it at each stage, you can un-comment (remove the semi-colon) at the start of each of the three MsgBox lines.


* I have assumed that the file CREATION date time is what is wanted. There are options in the FileGetTime instruction:
M = Modification time (this is the default if the parameter is omitted)
C = Creation time
A = Last access time


--- Code: Autohotkey ---;=============================================================^+G::  ; Ctrl+Shift+G grabs folder/file path to clipboard and puts CREATION date/time into Clipboard        FileDateTime := ""      ; define and clear variable        FileNamePath := ""      ; define and clear variable        SetTitleMatchMode, 2    ; match must be for specified string anywhere in the window Title name        IfWinActive,  xplorer² ; do this if xplorer² is the string in the active window Title        {        clipboard := "" ; clear clipboard        SendInput, ^c   ; copies file path and name to clipboard        ClipWait, 2 ; wait for up to 2 seconds for state change before proceeding, so as to ensure capture to clipboard;       MsgBox, 0, Pause 1 - Clipboard content, %Clipboard%     ; display clipboard text contents (for testing)        }        else    ; return (do nothing)        {        return        }        FileNamePath = %Clipboard%      ; puts just plain text of file name and path from clipboard into variable;       MsgBox, 0, Pause 2 - FileNamePath, %FileNamePath%       ; display variable text contents (for testing)        FileGetTime, FileDateTime, %FileNamePath%, C    ; get file CREATION date/time for named path/file        FormatTime, FileDateTime, %FileDateTime%, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353;       MsgBox, 0, Pause 3 - formatted FileDateTime, %FileDateTime%     ; display variable text contents        clipboard = %FileDateTime%      ; put the formatted date/time into clipboard        return;-------------------------------------------------------------------;============================================================

IainB:
Just corrected the AHK code above. I had forgotten to put the final (correct) code in. Sorry.

Navigation

[0] Message Index

[*] Previous page

Go to full version