Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

If i modify the folder within folders->subfolders it's not affecting the file modified time in pc.

For example i have a folder "folder3" under "folder2" under "folder1". I have written a code by accessing modified time of folder1. After some time if the folder3 modified by adding new files then the modified time of folder1 not changed and it's changed only folder2 modified time.

I need to get the latest modified time of root folder even subdirectories changed modified time. How can i do that. I tried using stat 8 and 9 option also but it's not showing me the last modify time.

Replies are listed 'Best First'.
Re: Folder modified time
by Utilitarian (Vicar) on Aug 28, 2009 at 13:16 UTC
    Works here,
    $ perl -e '$mtime=(stat("new_folder"))[9]; @date=localtime($mtime); $date[5] +=1900; $date[4] +=1; print "$date[5]-$date[4]-$date[3] $date[2]-$date[1]:$date[0]\n";' 2009-8-28 14-19:27 $ touch new_folder/test.file $ perl -e '$mtime=(stat("new_folder"))[9]; @date=localtime($mtime); $date[5] +=1900; $date[4] +=1; print "$date[5]-$date[4]-$date[3] $date[2]-$date[1]:$date[0]\n";' 2009-8-28 14-19:46
    What OS, which Perl etc..
Re: Folder modified time
by ikegami (Patriarch) on Aug 28, 2009 at 14:15 UTC

    Work on Windows too

    >md dir >perl -MFile::stat -le"print ''.localtime( stat('dir')->mtime )" Fri Aug 28 10:14:50 2009 >copy nul dir\file 1 file(s) copied. >perl -MFile::stat -le"print ''.localtime( stat('dir')->mtime )" Fri Aug 28 10:14:50 2009 >perl -MFile::stat -le"print ''.localtime( stat('dir')->mtime )" Fri Aug 28 10:15:06 2009

    But it took a second to update.

      That test doesn't seem to match his description. That would be more like:

      > md dir1 > md dir1\dir2 > copy nul dir1\dir2\file

      And he's expecting the mtime of dir1 to be updated after the copy.

        The system (NTFS + WinXP) doesn't appear to work that way.

        As you can see, the system says the parent directory (".") was last modified earlier than when the child directory ("dir2") was last modified:

        >dir dir1 Volume in drive C is C Volume Serial Number is 28AB-0E8B Directory of C:\Documents and Settings\ikegami\dir1 2009/08/28 12:43 PM <DIR> . 2009/08/28 12:43 PM <DIR> .. 2009/08/28 12:44 PM <DIR> dir2

        Perl reports the same.

      Ooh, much easier localtime by stringify, thanks for the technique, again
        Hi All, Thanks for sharing the thoughts. Now i achieved this by using FIle::Find::Rule to collect all the folders and i checked the latest modified time of all folders. but it's not a direct way and i checked for any direct way to find this time to save the script process time.