[761] in winnt

home help back first fref pref prev next nref lref last post

Determing whether a file is older/newer than a certian date.

daemon@ATHENA.MIT.EDU (Bryant C. Vernon)
Thu Dec 20 22:48:53 2001

Message-ID: <002801c189d2$0fe2e4f0$0100a8c0@mit.edu>
From: "Bryant C. Vernon" <bcvernon@MIT.EDU>
To: <winpartners@mit.edu>
Date: Thu, 20 Dec 2001 22:46:22 -0500
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0025_01C189A8.25F52B60"

This is a multi-part message in MIME format.

------=_NextPart_000_0025_01C189A8.25F52B60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All,

Here is a script I wrote for Eleanor Shavell from OSP. Her problem was =
identifying files that were updated after (I think) a certian date. The =
following script identifies files that were modified within the past x =
days. If you wanted to actually be able to enter an arbitrary date, then =
you would have to modify the script somewhat. You would have to subtract =
the target date from the current date in such a way to return the =
difference in days.=20

Eleanor, let me know if you want to be able to enter an arbitrary date =
(like 12/25/1997). I am assuming that the files of interest were =
modified reasonably recently (i.e. within the past 30-60 days), so it's =
easy to count. (obviously if you wanted to identify files modified 3 =
years ago, figuring out exactly how many days that equates to is quite =
annoying).

Bryant

checkmodified.pl
------------------------
#! c:\perl\bin\perl.exe

#Set the directory whose files you are analyzing.
$mydirectory=3D"c:\\temp";
#Set the number of days you want the check to go back
$days=3D7.0;

#Open the directory whose files we wish to analyze
opendir(MYDIRECTORYHANDLE, "$mydirectory") || die "Open directory error: =
$!";
#Make an array of all the filenames in the directory
@allfiles =3D readdir(MYDIRECTORYHANDLE);

#Initialize the counter
$n=3D0;

#Go through the array until we get to the end of it.
while (defined($allfiles[$n]))
{
#Use the -M operator to get the file's modification age in days. If it =
has been modified less than 7 days ago
#AND if it's not the directory link "." then let the world know!
    if ((-M "mydirectory\\$allfiles[$]" < $days) & ($allfiles[$n] ne =
"\."))
    {
        print "$allfiles has been modified within the past $days.\n";
    }
#Increment the counter.
n++;
}

------=_NextPart_000_0025_01C189A8.25F52B60
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi All,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is a script I wrote for Eleanor =
Shavell from=20
OSP. Her problem was identifying files that were updated after (I think) =
a=20
certian date. The following script identifies files that were modified =
within=20
the past x days. If you wanted to actually be able to enter an arbitrary =
date,=20
then you would have to modify the script somewhat. You would have to =
subtract=20
the target date from the current date in such a way to return the =
difference in=20
days. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Eleanor, let me know if you want to be =
able to=20
enter an arbitrary date (like 12/25/1997). I am assuming that the files =
of=20
interest were modified reasonably recently (i.e. within the past 30-60 =
days), so=20
it's easy to count. (obviously if you wanted to&nbsp;identify files=20
modified&nbsp;3 years ago, figuring out exactly how many days that =
equates to is=20
quite annoying).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Bryant</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>checkmodified.pl</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#! c:\perl\bin\perl.exe</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#Set the directory whose files you are=20
analyzing.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$mydirectory=3D"c:\\temp";</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#Set the number of days you want the =
check to go=20
back</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$days=3D7.0;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#Open the directory whose files we wish =
to=20
analyze</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>opendir(MYDIRECTORYHANDLE, =
"$mydirectory") || die=20
"Open directory error: $!";</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#Make an array of all the filenames in =
the=20
directory</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>@allfiles =3D=20
readdir(MYDIRECTORYHANDLE);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#Initialize the counter</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>$n=3D0;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#Go through the array until we get to =
the end of=20
it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>while =
(defined($allfiles[$n]))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#Use the -M operator to get the file's =
modification=20
age in days. If it has been modified less than 7 days ago</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#AND if it's not the directory link "." =
then let=20
the world know!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if ((-M=20
"mydirectory\\$allfiles[$]" &lt; $days) &amp; ($allfiles[$n] ne=20
"\."))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
print=20
"$allfiles has been modified within the past $days.\n";</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>#Increment the counter.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>n++;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV></BODY></HTML>

------=_NextPart_000_0025_01C189A8.25F52B60--



home help back first fref pref prev next nref lref last post