topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday April 17, 2024, 10:46 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: set folder modifed date/time to most recently modified file it contains  (Read 15995 times)

fhayes

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 19
    • View Profile
    • Donate to Member
When trying to keep directory trees in sync between local disks and network drives, it is confusing when some of the folder dates get changed by the move/copy operation. FileSync tools may ignore this but unfortunately my brain does not.
When looking at the source and destination directories I'd like the folder 'modified' date/time to reflect the most recently 'modified' file within that folder (tree). If the folder contains subfolders then it would be nice if it walked down the directory tree recursively modifying subdirectory timestamps and taking care of the entire tree. (Only the 'modified' timestamp would be altered)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
So, you want each folder modified-timestamp to be the timestamp of the most recently modified file just in that folder, or in the entire sub-folder tree?
- carpe noctem

fhayes

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 19
    • View Profile
    • Donate to Member
probably would be best to timestamp check just the files within the folder being viewed. Then when trying to figure out whats different across two dir trees you would know that if the folder dates differ, that the files that differ are at the next level down. This algorithm would then recurse down any discovered subdirectories checking their times to the times of the files found within them. Basically "fixing" the "broken" dates on the entire folder tree.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
this would be useful.

Crush

  • Member
  • Joined in 2006
  • **
  • Posts: 402
  • Hello dude!
    • View Profile
    • Read more about this member.
    • Donate to Member
I have some files here that contain NO kind of timestamp. This would be useful to repair these broken dates. Does someone also has found anything like this on his drives?

kwacky1

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 182
  • i am Cody's cousin
    • View Profile
    • CrazyLittleWebsite
    • Donate to Member
I have some files here that contain NO kind of timestamp. This would be useful to repair these broken dates. Does someone also has found anything like this on his drives?

Crush, you might find AnteDator useful for that purpose.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Crush: no timestamp? That sounds pretty messed up and basically impossible :-s
- carpe noctem

kwacky1

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 182
  • i am Cody's cousin
    • View Profile
    • CrazyLittleWebsite
    • Donate to Member
Crush: no timestamp? That sounds pretty messed up and basically impossible :-s

f0dder, not impossible with the above mention product  ;)

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • View Profile
    • Donate to Member
maybe this tool can fix the problem - Ninotech Date Edit.

"Ninotech Date Edit is a shell extension for Windows that enables you to change the date and time (the timestamp) of your files. You can change the created, modified, and accessed date of a file by right-clicking it in the Windows Explorer and choosing Edit Date from the context menu. By selecting multiple files in the Windows Explorer you are allowed to change the date/time of many files in just one action.

On Windows NT4, Windows 2000, and Windows XP you are also enabled to change the time and date of your directories."

http://home.worldonline.dk/ninotech/

PS. the website is not working currently.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
 :) Try MostRecent!

Select the start folder, and it will recurse the folder and set it's and all it's subfolders' modifed date/time to the most recently modified file or folder it contains.

Skrommel

;MostRecent.ahk
; Set folder modifed date/time to most recently modified file it contains.
; To run, save this script as MostRecent.ahk, and install AutoHotkey from www.autohotkey.com.
;Skrommel @ 2009

#NoEnv
#SingleInstance,Force

FileSelectFolder,folder,C:\,3,Select a folder to change the date/time of
TRAVERSE(folder)
Return


TRAVERSE(folder)
{
  mostrecent=0
  Loop,%folder%\*.*,1,0
  {
    IfInString,A_LoopFileAttrib,D
      childrecent:=TRAVERSE(A_LoopFileLongPath)
    If (childrecent>mostrecent)
      mostrecent:=childrecent
    If (A_LoopFileTimeModified>mostrecent)
      mostrecent:=A_LoopFileTimeModified
  }
  MsgBox,%mostrecent%`n%folder%
  FileSetTime,%mostrecent%,%folder%,M,2,0
  Return,%mostrecent%
}
« Last Edit: January 31, 2009, 06:13 AM by skrommel »

fhayes

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 19
    • View Profile
    • Donate to Member
Thank you Skrommel, that's excellent. That loop is a bit tricky, I definitely wouldn't have been able to come up with it. I forgot about this ask till tonight and was excited to see your solution posted here when I arrived back at this thread. It also got me back looking into AHK scripting, I've really got to find the time to get into this more, it's such a great tool. I made a few tweaks and added an output listing and repost it here. Thanks again!
; 1/31/09 authored by Skrommel www.donationcoder.com/Software/Skrommel (Very Nice, Thank You!)
; 3/06/09 fhayes
;         build and display list of changed dirs when program completes
;         improved error handling

;MostRecent.ahk
; Set folder modifed date/time to most recently modified file it contains.
; user selects the top of the folder tree to be processed
; only files in the immediate folder being processed effect that folders timestamp decision
; all subfolder in the tree are processed as well
; To run, save this script as MostRecent.ahk, and install AutoHotkey from www.autohotkey.com.
;Skrommel @ 2009

#NoEnv
#SingleInstance,Force

FileSelectFolder,folder,*C:\,3,Select a folder to change the date/time of
if ErrorLevel
  MsgBox,,,No folder selected,1
else
  {
  changelist := TRAVERSE(folder)
  header = ** press Control-C to copy this text to the clipboard **`n`n
  MsgBox,,List of updated directory timestamps,%header%%changelist%
  }
Return

TRAVERSE(folder)
{
  static filelist = ""
  mostrecent=0
  Loop,%folder%\*.*,1,0               ;include all files and folders, no recursion
  {
    IfInString,A_LoopFileAttrib,D             ;is this a directory
      childrecent:=TRAVERSE(A_LoopFileLongPath)
    If (childrecent>mostrecent)
      mostrecent:=childrecent
    If (A_LoopFileTimeModified>mostrecent)
      mostrecent:=A_LoopFileTimeModified
  }
  FileSetTime,%mostrecent%,%folder%,M,2,0 ;time modified,only folders,no recursion
  FormatTime, TimeString, %mostrecent%, MM/dd/yyyy hh:mm tt
  If (mostrecent<>0)                      ;if dir is not empty
    filelist = %filelist%%TimeString%`t%folder%`n  ;add to list
  Return (filelist)
}

FredThompson

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 3
    • View Profile
    • Donate to Member
This script seems to have a relatively low limit to the number of files which it will scan. The whole routine stops after about 1,000 files are checked. Is there a limit in AutoHotKey?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
If your folder chain time stamp situation doesn't need repair and you just want to sync folders with subfolders, I've found the sync tool in FreeCommander very simple to use in 2 base folder sync scenario. What I mean is you don't have to sync one source folder with 20 destination folders.  You have a folder on the left and one on the right. Sync with or without recursive subfolder sync.  Before you commit it shows a window with a display of which files will be copied in which direction and allows you to remove items from the list.

edit: although if you have thousands of files it may be cumbersome.  Works well for my needs.