;======================================================================= ; AutoHotKey script: TouchDirs.ahk (V1.0 08.08.06) ; ; set "modified" timestamp of a directory ; to the one of the newstest file OR directory in it ; propagate timestamps up the dir tree ; (empty dirs keep their timestamp) ; ; (possible extension: set "creation" timestamp to oldest file/dir) ; ; use script or parts of it as you like but at your own risk ; ; andreas lang, conTEXT AG, Zurich, Switzerland ;======================================================================= #SingleInstance ignore ; don't start script more than once ; globals mod = 0 ; flag to check if any timestamp update happened touched = 0 ; updated timestamp for that many dirs if 0 <> 1 ; exactly 1 parm required { msgBox usage: TouchDirs pathspec exit } dir = %1% IfNotExist, %dir% { msgBox can't find "%dir%" exit } StringRight, lastDirChar, dir, 1 ; fetch last char of dir If lastDirChar = \ { StringTrimRight, dir, dir, 1 ; chop trailing backslash } ; round 1: set dir date to the one of newest FILE in it TouchDirFromFiles(dir) ; round 2-n: set dir date to the one of newest SUBDIR in it passes = 1 Loop { ; do as long as any timestamp update happened If mod = 0 break Else { mod = 0 ; assume we're done TouchDirFromDirs(dir) ++passes } } msgBox %touched% dir(s) touched in %passes% pass(es). exit ;----------------------------------------------------------------------- ; functions ;----------------------------------------------------------------------- TouchDirFromFiles(dir) { global mod, touched actDir = %dir% FileGetTime, dirDate, %dir%, M Loop, %dir%\*.*, 1, 0 ; loop over files AND folders, no recursion { FileGetAttrib, attr, %A_LoopFileLongPath% IfNotInString, attr, D ; file: process { If A_LoopFileTimeModified > %dirDate% ; file newer than dir { FileSetTime, %A_LoopFileTimeModified%, %actDir%, M, 2, 0 dirDate = %A_LoopFileTimeModified% ; remember new dir date mod = 1 ; timestamp updated ++touched } } Else ; dirs { TouchDirFromFiles(A_LoopFileLongPath) ; drill down } } } ;----------------------------------------------------------------------- TouchDirFromDirs(dir) { global mod, touched actDir = %dir% FileGetTime, dirDate, %dir%, M Loop, %dir%\*.*, 2, 0 ; loop over folders only, no recursion { If A_LoopFileTimeModified > %dirDate% ; newer than parent { StringRight, lastDirChar, dir, 1 ; fetch last char of dir If lastDirChar <> : ; if not drive itself { FileSetTime, %A_LoopFileTimeModified%, %actDir%, M, 2, 0 dirDate = %A_LoopFileTimeModified% ; remember new dir date mod = 1 ; timestamp updated ++touched } } TouchDirFromDirs(A_LoopFileLongPath) ; drill down } } ;=======================================================================

TouchDirs: update "modified" timestamps of a direc
Started by
andreas
, Aug 08 2006 02:28 PM
3 replies to this topic
my 1st AHK script, hoping it may be useful for somebody else as well ...
#1
-
Posted 08 August 2006 - 02:28 PM

line 6 should obviously start with a ; instead of :
sorry, andreas
(note from moderator: it has been fixed in the post above)
sorry, andreas
(note from moderator: it has been fixed in the post above)
#2
-
Posted 08 August 2006 - 02:48 PM

Hehe...I noticed that too.
I remember writing a script like this, but I called it "violate.exe" instead of touch... :wink:
I remember writing a script like this, but I called it "violate.exe" instead of touch... :wink:
#3
-
Posted 09 August 2006 - 01:05 AM

//TODO: Create kewl sig...
GUIed version of TouchDirs
same functionality as in the command line version above
same functionality as in the command line version above
;======================================================================= ; AutoHotKey script: TouchFolders.ahk (V1.0 14.08.06) ; ; set "modified" timestamp of a directory ; to the one of the newstest file OR directory in it ; propagate timestamps up the dir tree ; (empty dirs keep their timestamp) ; ; (possible extension: set "creation" timestamp to oldest file/dir) ; ; use script or parts of it as you like but at your own risk ; ; andreas lang, conTEXT AG, Zurich, Switzerland ;======================================================================= #SingleInstance ignore ; don't start script more than once ; globals mod = 0 ; flag to check if any timestamp update happened touched = 0 ; updated timestamp for that many dirs FileSelectFolder, dir, *C:\, 0 ; don't allow making new folder if ErrorLevel or dir = { msgBox no folder selected. exit! exit } StringRight, lastDirChar, dir, 1 ; fetch last char of dir If lastDirChar = \ { StringTrimRight, dir, dir, 1 ; chop trailing backslash } ; round 1: set dir date to the one of newest FILE in it TouchDirFromFiles(dir) ; round 2-n: set dir date to the one of newest SUBDIR in it passes = 1 Loop { ; do as long as any timestamp update happened If mod = 0 break Else { mod = 0 ; assume we're done TouchDirFromDirs(dir) ++passes } } msgBox %touched% dir(s) touched in %passes% pass(es). exit ;----------------------------------------------------------------------- ; functions ;----------------------------------------------------------------------- TouchDirFromFiles(dir) { global mod, touched actDir = %dir% FileGetTime, dirDate, %dir%, M Loop, %dir%\*.*, 1, 0 ; loop over files AND folders, no recursion { FileGetAttrib, attr, %A_LoopFileLongPath% IfNotInString, attr, D ; file: process { If A_LoopFileTimeModified > %dirDate% ; file newer than dir { FileSetTime, %A_LoopFileTimeModified%, %actDir%, M, 2, 0 dirDate = %A_LoopFileTimeModified% ; remember new dir date mod = 1 ; timestamp updated ++touched } } Else ; dirs { TouchDirFromFiles(A_LoopFileLongPath) ; drill down } } } ;----------------------------------------------------------------------- TouchDirFromDirs(dir) { global mod, touched actDir = %dir% FileGetTime, dirDate, %dir%, M Loop, %dir%\*.*, 2, 0 ; loop over folders only, no recursion { If A_LoopFileTimeModified > %dirDate% ; newer than parent { StringRight, lastDirChar, dir, 1 ; fetch last char of dir If lastDirChar <> : ; if not drive itself { FileSetTime, %A_LoopFileTimeModified%, %actDir%, M, 2, 0 dirDate = %A_LoopFileTimeModified% ; remember new dir date mod = 1 ; timestamp updated ++touched } } TouchDirFromDirs(A_LoopFileLongPath) ; drill down } } ;=======================================================================
#4
-
Posted 29 November 2006 - 07:58 AM
