Skip to content

Instantly share code, notes, and snippets.

@langheran
Created July 31, 2024 01:04
Show Gist options
  • Save langheran/60d038f034dac6465ff4df12cdd6dd70 to your computer and use it in GitHub Desktop.
Save langheran/60d038f034dac6465ff4df12cdd6dd70 to your computer and use it in GitHub Desktop.
C:\Users\NisimHurst\Utilities\Autohotkey\SetFolderTimestampToNewestFile\SetFolderTimestampToNewestFile.ahk
; 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%
setCurrentFolder(sFolder)
Return
setCurrentFolder(sFolder){
dTimestamp := "19000101"
bThereIsFile := False
Loop, Files, %sFolder%\*, FD
{
if (InStr(A_LoopFileAttrib, "D")){
setCurrentFolder(A_LoopFileFullPath)
}
FileGetTime, dFileTime, %A_LoopFileFullPath%
if (dTimestamp < dFileTime){
bThereIsFile := True
dTimestamp := dFileTime
}
; if (dTimestamp < A_LoopFileTimeModified)
; dTimestamp := A_LoopFileTimeModified
}
if (bThereIsFile)
FileSetTime %dTimestamp%, %sFolder%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment