Welcome Guest.   Make a donation to an author on the site October 02, 2014, 09:36:03 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2012! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: AHK script to insert date and time to file name  (Read 7185 times)
wetsmellydog
Participant
*
Posts: 97

View Profile Give some DonationCredits to this forum member
« on: June 25, 2010, 11:30:46 AM »

While backing up some info today, I thought how cumbersome it is to type the date and time into the file name. It would be nice to have a shortcut that could do that.
Yes I know there is a time/date stamp on the file BUT this makes the file name unique too.

EX:

            "inserted text"
foobar 06_25_10 9-30am (does not have to follow this exact format just an idea)

Apologies up front if this has already been done but unfortunately I have not been able to find it.

Thanks!
Larry
Logged
lanux128
Global Moderator
*****
Posts: 6,102



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: June 25, 2010, 11:53:32 AM »

is this what you're looking for? TimeStamp 2.1 by Skrommel..

• http://www.donationcoder....13669.msg116805#msg116805
Logged

wetsmellydog
Participant
*
Posts: 97

View Profile Give some DonationCredits to this forum member
« Reply #2 on: June 25, 2010, 12:19:34 PM »

is this what you're looking for? TimeStamp 2.1 by Skrommel..

• http://www.donationcoder....13669.msg116805#msg116805

Thanks for the link. Will have to take a look...one thing I notice is the formatting...certain characters are no no for file naming.
Logged
lanux128
Global Moderator
*****
Posts: 6,102



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: June 25, 2010, 12:23:19 PM »

yes, that script was originally made to be pasted in the active window but in your case, the reserved characters should be excluded.

Quote
The following reserved characters are not allowed in file/folder naming: ! @ # $ % ^ & * ( ) + = ~ ` < > : " / \ | ? *

Logged

IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #4 on: June 25, 2010, 12:26:26 PM »

I use this - prune it how you like.
Having the date in ISO format at the front of the file name makes for good document filing/sorting.

AutoHotKey script:
Quote
^+d::  ; Ctrl+Shift+d outputs current date+time
   FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
   return
Logged
wetsmellydog
Participant
*
Posts: 97

View Profile Give some DonationCredits to this forum member
« Reply #5 on: June 25, 2010, 01:12:07 PM »

I use this - prune it how you like.
Having the date in ISO format at the front of the file name makes for good document filing/sorting.

AutoHotKey script:
Quote
^+d::  ; Ctrl+Shift+d outputs current date+time
   FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
   return

Sweet!  Thmbsup

Thanks! Hopefully I will have more time to work on learning AHK to be able to know that it takes a whole two lines of code to do this!

BTW works like a charm.
« Last Edit: June 25, 2010, 01:18:01 PM by wetsmellydog » Logged
IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: June 26, 2010, 11:21:38 PM »

@wetsmellydog: Thanks for your thanks. I cannot take credit for this as being "all my own work" though!

I actually lifted some AHK code from somewhere else (I forget where), and then later - after taking the time to discover/learn more about AHK - I simplified and modified the code to suit my particular requirements. So what you see is what I ended up with.

The sources I used were:

These are all good. The tutorials I came across were very helpful.

As an encouragement, I would suggest that you might pick it up quite quickly if you have no techo background to cloud your thinking with preconceptions.

You might think it would help to have a techo background, but sometimes I am not so sure.

For example, take my case: Having been introduced to computer programming via a low-level programming language used for assembler programming on mainframe computers years ago, I have always had difficulty changing my thinking to use any higher-level languages. It was thus difficult for me when I later had to adapt and learn to program in the programming language FORTRAN (which has to be compiled before execution), but when I learned the BASIC language it seemed quite foreign (it is not compiled, but runs through an interpreter at run-time). Years later, I had similar difficulty wrapping my mind around a scripting language (I think it was called "Telix") to control and manipulate data flowing between the PC serial port and a modem (driven by the Hayes AT command set).
So, when I came across AHK, though it at least had a degree of familiarity in its general structure, I had to push to one side everything that I had previously learned, lest it get in the way of my understanding this new thing.

You might not have that difficulty, from the sound of things.
Interestingly, from what I have read, a lot of the PC viruses over the years are apparently thought to have been developed by "script-kiddies" - virgins whose first PC programming language was a scripting language.
Logged
wetsmellydog
Participant
*
Posts: 97

View Profile Give some DonationCredits to this forum member
« Reply #7 on: June 28, 2010, 04:19:42 PM »

IainB "As an encouragement, I would suggest that you might pick it up quite quickly if you have no techo background to cloud your thinking with preconceptions."

No truer words were ever spoken!

I am an electronics engineer by trade and now a nurse. My specialty was automation and controls.

It has been tough to wrap my mind around how they want "nurses" to think. What seems simple to the people who do not have a technical background take on a whole new meaning to me.   huh

I am far ahead of what they are expecting and I have to remember to go from a to b to c instead of jumping right into c because I "know" it is right. I have also been working in the medical field for the last 4 years which also hinders that KISS thinking.

Some of us think in binary and some of us think in analog and some of us keep confusing the 10!!
Logged
metaDCoder
Participant
*
Posts: 2


View Profile Give some DonationCredits to this forum member
« Reply #8 on: February 16, 2014, 04:37:44 PM »

Hi, I wonder if you could maybe mod this:
[copy or print]
^+d::  ; Ctrl+Shift+d outputs current date+time
   FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
   return

So that it would rather copy to the clipboard the ISO formatted timestamp as given by attributes/properties (rather than CURRENT timestamp).

Thanks
Logged
IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #9 on: February 17, 2014, 02:08:16 AM »

You'd be able to use AHK FileGetTime for that:
From the Help file:
Parameters
  • OutputVar: The name of the variable in which to store the retrieved date-time in format YYYYMMDDHH24MISS. The time is your own local time, not UTC/GMT.
  • Filename: The name of the target file or folder, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. If omitted, the current file of the innermost enclosing File-Loop will be used instead.
  • WhichTime: Which timestamp to retrieve:
    M = Modification time (this is the default if the parameter is omitted)
    C = Creation time
    A = Last access time

I haven't used it in an AHK script, but it should presumably work fine.
First, you'd need to decide which of the three file date/times you wanted to retrieve by default - M, C, or A.
The new bit for me would be pinpointing the input file from which to take the date/time.
Logged
rjbull
Charter Member
***
Posts: 2,760

View Profile Give some DonationCredits to this forum member
« Reply #10 on: February 17, 2014, 03:39:37 PM »

it would rather copy to the clipboard the ISO formatted timestamp
You might like to look at Horst Schaeffer's freeware Calendar which allows you to roll your own formats and have them available from a drop-down.  E.g.:
      
Logged
tomos
Charter Member
***
Posts: 8,554



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: February 17, 2014, 04:12:54 PM »

Hi, I wonder if you could maybe mod this:
[copy or print]
^+d::  ; Ctrl+Shift+d outputs current date+time
   FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
   return

So that it would rather copy to the clipboard the ISO formatted timestamp as given by attributes/properties (rather than CURRENT timestamp).

FWIW, I have an older script (2008...)
[edit] which did something completely different embarassed (pasted current date/time [/edit]
« Last Edit: February 28, 2014, 04:03:17 AM by tomos » Logged

Tom
metaDCoder
Participant
*
Posts: 2


View Profile Give some DonationCredits to this forum member
« Reply #12 on: February 18, 2014, 02:20:42 PM »

Hi guys, I just wanted to thank you for your comments and suggestions concerning my question (of inserting attributes:time_stamp into the clipboard, and eventually filename).   smiley

@IainB - I appreciate the references on the proper functions to use. I don't think it will be so hard now for me to write a functioning script.  Check out http://www.autohotkey.com...ath-for-files-on-desktop/ for a super-simple method of retrieving file-path. Note that that script breaks if trying to use the hot-key with no file/folder selected.

Logged
IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #13 on: February 18, 2014, 04:18:55 PM »

@metaDCoder: Ah, thanks for that link to http://www.autohotkey.com...ath-for-files-on-desktop/
I shall write/try out a script for this idea and post it here when I get it to work.
Logged
4wd
Supporting Member
**
Posts: 3,338



see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #14 on: February 18, 2014, 07:18:06 PM »

Don't know if you're familiar with AutoIt but I just added a few lines to a script I modified here.

Only for Explorer.  (Most decent file managers would do this type of thing already, ie. insert file dates, meta data into a rename function.)

Shift+Alt+V - copies the file path/name of the first selected item in an Explorer window, (file or folder), or if nothing is selected then it copies the current Explorer path to the clipboard.

Shift+Alt+D - copies the MODIFIED date of the selected item, (or Explorer path if nothing selected), into the clipboard in Universal format: YYYYMMDD HHMMSS  (NOTE: Won't capture the date of root directories.)

The hotkeys, type of date retrieved, and it's output format could all be changed in the source.

Formatted for AutoIt with the GeSHI Syntax Highlighter [copy or print]
  1. #region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_UseUpx=n
  3. #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
  4. ; http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__st__40#entry973904
  5. #include <Array.au3>
  6.  
  7. HotKeySet('+!v', '_HK_Path') ; Shift+Alt+V
  8. HotKeySet('+!d', '_HK_Date') ; Shift+Alt+D
  9.  
  10. Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc")
  11.  
  12. Sleep(100)
  13.  
  14. Func _HK_Path()
  15. _ExClip(False)
  16. EndFunc   ;==>_HK_Path
  17.  
  18. Func _HK_Date()
  19. _ExClip(True)
  20. EndFunc   ;==>_HK_Date
  21.  
  22. Func _ExClip($temp)
  23. $hExplr = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]")
  24. If $hExplr <> '' Then
  25. $aSelection = _ExplorerWinGetSelectedItems($hExplr)
  26. ;~ _ArrayDisplay($aSelection)
  27. If $aSelection[0] = 0 Then
  28. If StringLeft($aSelection[1], 2) <> '::' Then
  29. If Not $temp Then
  30. ClipPut($aSelection[1])
  31. $sDate = FileGetTime($aSelection[1], 0, 1) ; Get MODIFIED date (0), change 0 to 1 for CREATED, 2 for ACCESSED
  32. ClipPut(StringLeft($sDate, 8) & " " & StringMid($sDate, 9))
  33. If Not $temp Then
  34. ClipPut($aSelection[2])
  35. $sDate = FileGetTime($aSelection[2], 0, 1) ; Get MODIFIED date (0) (0), change 0 to 1 for CREATED, 2 for ACCESSED
  36. ClipPut(StringLeft($sDate, 8) & " " & StringMid($sDate, 9))
  37. EndFunc   ;==>_ExClip
  38.  
  39.  
  40.  
  41. ; ==========================================================================================================================
  42.  
  43. ; Func _ObjectSHFolderViewFromWin($hWnd)
  44. ;
  45. ; Returns an 'ShellFolderView' Object for the given Window handle
  46. ;
  47. ; Author: Ascend4nt, based on code by KaFu, klaus.s
  48. ; ==========================================================================================================================
  49.  
  50. Func _ObjectSHFolderViewFromWin($hWnd)
  51. If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0)
  52. Local $oShell, $oShellWindows, $oIEObject, $oSHFolderView
  53.  
  54. ; Shell Object
  55. $oShell = ObjCreate("Shell.Application")
  56. If Not IsObj($oShell) Then Return SetError(2, 0, 0)
  57.  
  58. ;   Get a 'ShellWindows Collection' object
  59. $oShellWindows = $oShell.Windows()
  60. If Not IsObj($oShellWindows) Then Return SetError(3, 0, 0)
  61.  
  62. ;   Iterate through the collection - each of type 'InternetExplorer' Object
  63.  
  64. For $oIEObject In $oShellWindows
  65. If $oIEObject.HWND = $hWnd Then
  66. ; InternetExplorer->Document = ShellFolderView object
  67. $oSHFolderView = $oIEObject.Document
  68. If IsObj($oSHFolderView) Then Return $oSHFolderView
  69. Return SetError(4, 0, 0)
  70.  
  71. Return SetError(-1, 0, 0)
  72. EndFunc   ;==>_ObjectSHFolderViewFromWin
  73.  
  74. ; ==========================================================================================================================
  75. ; Func _ExplorerWinGetSelectedItems($hWnd)
  76. ;
  77. ;
  78. ; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification)
  79. ; ==========================================================================================================================
  80.  
  81. Func _ExplorerWinGetSelectedItems($hWnd)
  82. If Not IsHWnd($hWnd) Then Return SetError(1, 0, '')
  83. Local $oSHFolderView
  84. Local $iSelectedItems, $iCounter = 2, $aSelectedItems[2] = [0, ""]
  85.  
  86. $oSHFolderView = _ObjectSHFolderViewFromWin($hWnd)
  87.  
  88. ;   SelectedItems = FolderItems Collection object->Count
  89. $iSelectedItems = $oSHFolderView.SelectedItems.Count
  90.  
  91. Dim $aSelectedItems[$iSelectedItems + 2] ; 2 extra -> 1 for count [0], 1 for Folder Path [1]
  92.  
  93. $aSelectedItems[0] = $iSelectedItems
  94. ;   ShellFolderView->Folder->Self as 'FolderItem'->Path
  95. $aSelectedItems[1] = $oSHFolderView.Folder.Self.Path
  96.  
  97. ;   ShellFolderView->SelectedItems = FolderItems Collection object
  98. $oSelectedFolderItems = $oSHFolderView.SelectedItems
  99.  
  100. #cs
  101. ; For ALL items in an Explorer Window (not just the selected ones):
  102. $oSelectedFolderItems = $oSHFolderView.Folder.Items
  103. ReDim $aSelectedItems[$oSelectedFolderItems.Count+2]
  104. #ce
  105.  
  106. For $oFolderItem In $oSelectedFolderItems
  107. $aSelectedItems[$iCounter] = $oFolderItem.Path
  108. $iCounter += 1
  109.  
  110. Return SetExtended($iCounter - 2, $aSelectedItems)
  111. EndFunc   ;==>_ExplorerWinGetSelectedItems
  112.  
  113. Func _ComErrFunc($oError)
  114. ConsoleWrite("COM Error occurred:" & @CRLF & _
  115. "Number: " & @TAB & $oError.number & @CRLF & _
  116. "Windescription:" & @TAB & $oError.windescription & @CRLF & _
  117. "Description is: " & @TAB & $oError.description & @CRLF & _
  118. "Source is: " & @TAB & $oError.source & @CRLF & _
  119. "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
  120. "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
  121. "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
  122. "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
  123. "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
  124. EndFunc   ;==>_ComErrFunc

* ExClip.7z (261.69 KB - downloaded 49 times.)
Logged

I do not need to control my anger ... people just need to stop pissing me off!
IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #15 on: February 18, 2014, 08:44:20 PM »

@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

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  1. ;=============================================================
  2. ^+G::  ; Ctrl+Shift+G grabs folder/file path to clipboard and puts CREATION date/time into Clipboard
  3. FileDateTime := "" ; define and clear variable
  4. FileNamePath := "" ; define and clear variable
  5. SetTitleMatchMode, 2 ; match must be for specified string anywhere in the window Title name
  6. IfWinActive,  xplorer² ; do this if xplorer² is the string in the active window Title
  7. {
  8. clipboard := "" ; clear clipboard
  9. SendInput, ^c ; copies file path and name to clipboard
  10. ClipWait, 2 ; wait for up to 2 seconds for state change before proceeding, so as to ensure capture to clipboard
  11. ; MsgBox, 0, Pause 1 - Clipboard content, %Clipboard% ; display clipboard text contents (for testing)
  12. }
  13. else ; return (do nothing)
  14. {
  15. }
  16. FileNamePath = %Clipboard% ; puts just plain text of file name and path from clipboard into variable
  17. ; MsgBox, 0, Pause 2 - FileNamePath, %FileNamePath% ; display variable text contents (for testing)
  18. FileGetTime, FileDateTime, %FileNamePath%, C ; get file CREATION date/time for named path/file
  19. FormatTime, FileDateTime, %FileDateTime%, yyyy-MM-dd HHmm  ; It will look like 2010-12-21 0353
  20. ; MsgBox, 0, Pause 3 - formatted FileDateTime, %FileDateTime% ; display variable text contents
  21. clipboard = %FileDateTime% ; put the formatted date/time into clipboard
  22. ;-------------------------------------------------------------------
  23. ;============================================================
« Last Edit: February 27, 2014, 11:41:29 PM by IainB; Reason: CORRECTION to code: 2014-02-28 1837hrs » Logged
IainB
Supporting Member
**
Posts: 4,759


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #16 on: February 27, 2014, 11:42:46 PM »

Just corrected the AHK code above. I had forgotten to put the final (correct) code in. Sorry.
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.178s | Server load: 0.22 ]