[762] in winnt
Re: Determing whether a file is older/newer than a certian
daemon@ATHENA.MIT.EDU (Eleanor)
Fri Dec 21 12:21:30 2001
Message-Id: <5.0.2.1.2.20011221105455.01bf7758@po14.mit.edu>
Date: Fri, 21 Dec 2001 12:20:14 -0500
To: "Bryant C. Vernon" <bcvernon@mit.edu>
From: Eleanor <ele@MIT.EDU>
Cc: winpartners@mit.edu
In-Reply-To: <002801c189d2$0fe2e4f0$0100a8c0@mit.edu>
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="=====================_952529384==_.ALT"
--=====================_952529384==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed
Hi,
Thanks Bryant...I tried running the script and found a couple of errors
which seemed to be typos..
(1) - if ((-M "mydirectory\\$allfiles[$]" < $days) &
($allfiles[$n] ne "\.")) should be ...$allfiles[$n]
(2) - n++ should be $n++
(3) - print $allfiles should be print $allfiles[$n]..
Can you tell me where I can find information about the -M operator you
used? I am really just hacking around in Perl, not having gone thru any of
the tutorials or anything...so if my questions are too elementary, just
tell me and I'll stop asking them!!!
But if not, then read on...
I tried the following script.. and it worked...any comments? Basically I'm
trying to find all files modified after a certain date and copy them....
#! c:\perl\bin\perl.exe
## find all files whose modify date is after some date
## and copy them to another directory
use File::Copy;
use Date::Manip;
# this seems to be needed for the date manip stuff to work
&Date_Init("TZ=EST");
$source_dir = 'f:\ele\Eudora';
$target_dir = 'c:\perl_test\NewFolder';
$cutOffDate = &ParseDate("12/18/2001");
opendir(DIR,"$source_dir") || die "Can not open $source_dir";
@entries = readdir(DIR);
closedir (DIR);
$n= 0;
# this seems to be necessary
chdir $source_dir || die "can not change directory";
while (defined(@entries[$n]))
{
$filename = @entries[$n];
# found references to the stat command while snooping around,
# so thats what i'm using
($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($filename);
#mode 33206 seems to be a file, rather than a directory..
if ($mode eq 33206)
{
# print "file name : $filename ";
# print "last modify : $mtime \n";
$date = &ParseDateString("epoch $mtime");
$flag = &Date_Cmp($date,$cutOffDate);
if ($flag < 0) {
print "$filename is earlier \n";
} elsif ($flag ==0) {
print "dates are the same \n";
} else {
print "$filename is later \n";
copy ($filename, $target_dir) || die "no can copy\n";
}
}
$n++;
}
At 10:46 PM 12/20/2001 -0500, you wrote:
>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.
>
>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="c:\\temp";
>#Set the number of days you want the check to go back
>$days=7.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 = readdir(MYDIRECTORYHANDLE);
>
>#Initialize the counter
>$n=0;
>
>#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++;
>}
--=====================_952529384==_.ALT
Content-Type: text/html; charset="us-ascii"
<html>
Hi,<br>
Thanks Bryant...I tried running the script and found a
couple of errors which seemed to be typos..<br>
<br>
<font face="arial" size=2> <x-tab> </x-tab>(1)
- if ((-M
"mydirectory\\</font><font face="arial" size=2 color="#0000FF">$allfiles[$]</font><font face="arial" size=2>"
< $days) & ($allfiles[$n] ne "\.")) should
be
...</font><font face="arial" size=2 color="#0000FF">$allfiles[$n]<br>
</font><x-tab> </x-tab>(2)
- n++ should be $n++<br>
(3) - print
$allfiles should be print $allfiles[$n]..<br>
<br>
Can you tell me where I can find information about the -M operator you
used? I am really just hacking around in Perl, not having gone thru
any of the tutorials or anything...so if my questions are too elementary,
just tell me and I'll stop asking them!!!<br>
<br>
But if not, then read on...<br>
I tried the following script.. and it worked...any comments? Basically
I'm trying to find all files modified after a certain date and copy
them....<br>
<br>
#! c:\perl\bin\perl.exe<br>
<br>
## find all files whose modify date is after some date<br>
## and copy them to another directory<br>
<br>
use <a href="file::Copy" eudora="autourl">File::Copy</a>;<br>
use Date::Manip;<br>
<br>
# this seems to be needed for the date manip stuff to work<br>
&Date_Init("TZ=EST");<br>
<br>
$source_dir = 'f:\ele\Eudora';<br>
$target_dir = 'c:\perl_test\NewFolder';<br>
$cutOffDate = &ParseDate("12/18/2001");<br>
<br>
opendir(DIR,"$source_dir") || die "Can not open
$source_dir";<br>
@entries = readdir(DIR);<br>
closedir (DIR);<br>
<br>
$n= 0;<br>
<br>
# this seems to be necessary<br>
chdir $source_dir || die "can not change directory";<br>
<br>
while (defined(@entries[$n]))<br>
{ <br>
$filename = @entries[$n];<br>
<br>
# found references to the stat command while snooping around,<br>
# so thats what i'm using<br>
<br>
($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $size,<br>
$atime, $mtime, $ctime, $blksize, $blocks) =
stat($filename);<br>
<br>
#mode 33206 seems to be a file, rather than a directory..<br>
<br>
if ($mode eq 33206) <br>
{<br>
# print "file
name : $filename ";<br>
# <x-tab> </x-tab>print "last
modify : $mtime \n";<br>
<br>
<x-tab> </x-tab>$date =
&ParseDateString("epoch $mtime"); <br>
<x-tab> </x-tab>$flag =
&Date_Cmp($date,$cutOffDate);<br>
<br>
<x-tab> </x-tab>if ($flag
< 0) {<br>
<x-tab> </x-tab>
print "$filename is earlier \n";<br>
<x-tab> </x-tab>}
elsif ($flag ==0) {<br>
<x-tab> </x-tab>
print "dates are the same \n";<br>
<x-tab> </x-tab>}
else {<br>
<x-tab> </x-tab>
print "$filename is later \n";<br>
<x-tab> </x-tab>
<br>
<x-tab> </x-tab>
copy ($filename, $target_dir) || die "no can copy\n";<br>
<x-tab> </x-tab>}<br>
<x-tab> </x-tab> <br>
} <br>
$n++;<br>
}<br>
<br>
<br>
<br>
At 10:46 PM 12/20/2001 -0500, you wrote:<br>
<blockquote type=cite class=cite cite><font face="arial" size=2>Hi
All,</font><br>
<br>
<font face="arial" size=2>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. </font><br>
<br>
<font face="arial" size=2>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).</font><br>
<br>
<font face="arial" size=2>Bryant</font><br>
<br>
<font face="arial" size=2>checkmodified.pl</font><br>
<font face="arial" size=2>------------------------</font><br>
<font face="arial" size=2>#! c:\perl\bin\perl.exe</font><br>
<br>
<font face="arial" size=2>#Set the directory whose files you are
analyzing.</font><br>
<font face="arial" size=2>$mydirectory="c:\\temp";</font><br>
<font face="arial" size=2>#Set the number of days you want the check to
go back</font><br>
<font face="arial" size=2>$days=7.0;</font><br>
<br>
<font face="arial" size=2>#Open the directory whose files we wish to
analyze</font><br>
<font face="arial" size=2>opendir(MYDIRECTORYHANDLE,
"$mydirectory") || die "Open directory error:
$!";</font><br>
<font face="arial" size=2>#Make an array of all the filenames in the
directory</font><br>
<font face="arial" size=2>@allfiles =
readdir(MYDIRECTORYHANDLE);</font><br>
<br>
<font face="arial" size=2>#Initialize the counter</font><br>
<font face="arial" size=2>$n=0;</font><br>
<br>
<font face="arial" size=2>#Go through the array until we get to the end
of it.</font><br>
<font face="arial" size=2>while (defined($allfiles[$n]))</font><br>
<font face="arial" size=2>{</font><br>
<font face="arial" size=2>#Use the -M operator to get the file's
modification age in days. If it has been modified less than 7 days
ago</font><br>
<font face="arial" size=2>#AND if it's not the directory link
"." then let the world know!</font><br>
<font face="arial" size=2> if ((-M
"mydirectory\\$allfiles[$]" < $days) & ($allfiles[$n] ne
"\."))</font><br>
<font face="arial" size=2> {</font><br>
<font face="arial" size=2>
print "$allfiles has been modified within the past
$days.\n";</font><br>
<font face="arial" size=2> }</font><br>
<font face="arial" size=2>#Increment the counter.</font><br>
<font face="arial" size=2>n++;</font><br>
<font face="arial" size=2>}</font></blockquote></html>
--=====================_952529384==_.ALT--