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

On Win32 , how do you determine the last MODIFIED date of a folder? I'm putting together a script that will list certain directories that have been modified within the last 'x' days.

I know that the Win32 filesystem does keep this information, but even in the Win32 modules, I can;t find any documentation.

Thanks in advance.
  • Comment on How to determine the last modified date for a directory?

Replies are listed 'Best First'.
Re: How to determine the last modified date for a directory?
by tachyon (Chancellor) on Jul 31, 2001 at 21:17 UTC

    You can do it with the -M file test operator which returns result in floating point decimal days.

    $dir = "c:/windows"; $age = -M $dir; print "Dir $dir was last modified $age days ago\n"; # make a new dir just for fun $dir = "c:/foo"; mkdir $dir; $age = -M $dir; print "Dir $dir was last modified $age days ago\n"; rmdir $dir; # delete this test dir

    With a dir the concept of modification is a little nebulous - it is actually the days since it was created.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Is the modification time for a directory dependent on the Windows version? WinNT SP6a, at least, updates the modification time when the directory permissions change, a file is added, updated or deleted.

      Have fun,
      Carl Forde

        You have these options:

        -d True if file is a directory -M Age of file in days when script started. -A Same for access time. -C Same for inode change time.

        I tested this on a Win 95 box cause thats what is in front of me here. As Win 95/98 has little concept of permissons it will quite probably be different to NT which is basically a totally different OS. A little quick testing will show you what is happening, like the example above. You can add some dirs/files, change the permissions, add some sleeps and compare results of -M -A -C in a few lines to get the results you want.

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: How to determine the last modified date for a directory?
by Anonymous Monk on Jul 31, 2001 at 21:40 UTC
    You can also use stat()
    my ($full_dir, @stat); $full_dir="c:\\projectstuff"; (@stat)=stat("$full_dir"); print scalar(localtime($stat[10]));