AutoHotkey: Set folder timestamp to newest file

From TotalcmdWiki
Jump to: navigation, search

This script can be used as a shell extension to folders (it appears in the right click menu of a folder). There is no need to compile the script, but because it can be useful, the reg script contains that alternative as well (just comment/uncomment the respective lines).

; SetFolderTimestampToNewestFile.ahk
;   by SanskritFritz
; Set a folder's 'modified' date to the timestamp of the newest file it contains.
; The folder name should be given as parameter.


if 0 <> 1
	MsgBox The parameter 'folder name' is missing!
sFolder = %1%

dTimestamp := "19000101"
bThereIsFile := False
loop %sFolder%\*
	bThereIsFile := True
	if (dTimestamp < A_LoopFileTimeModified)
		dTimestamp := A_LoopFileTimeModified
if (bThereIsFile)
	FileSetTime %dTimestamp%, %sFolder%

Here is the registry script:


[HKEY_CLASSES_ROOT\Directory\shell\Adjust Timestamp]

[HKEY_CLASSES_ROOT\Directory\shell\Adjust Timestamp\command]
@="\"c:\\Program Files\\AutoHotkey\\AutoHotkey.exe\" \"x:\\AutoHotkey\\SetFolderTimestampToNewestFile.ahk\" \"%1\""
;If the script is compiled:
;@="\"x:\\Autohotkey\\SetFolderTimestampToNewestFile.exe\" \"%1\""

Back to AutoHotkey