AutoHotkey: Set folder timestamp to newest file

From TotalcmdWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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.

#NoTrayIcon

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

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

Here is the registry script:

REGEDIT4

[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