Front page | perl.beginners |
Postings from March 2002
RE: finding example scripts
Thread Previous
|
Thread Next
From:
Louden, Chris
Date:
March 5, 2002 11:45
Subject:
RE: finding example scripts
Message ID:
BFC425F23391D511A00300508B604BF5073A2F01@nlv-exchange3.nv.doe.gov
Here is what I have so far. It works on an NT PC running Perl from Active
State, but I need to run it on a Novell box. Paths to directories are
different. Im not sure how to type in the paths, the standard
"servername:volume/path/to/dir" does not seem to work. This checks for files
modified in the previous hour on the E drive and moved them to a d:\backups\
#!/usr/local/bin/perl
use File::stat;
use File::Copy;
use File::Path;
$now = time;
($SEC, $MIN, $HOUR, $MDAY, $MON, $YEAR, $WDAY,
$YDAY, $ISDAYLITE)= localtime();
$DAY = sprintf("%02d-%02d-%02d", ++$MON, $MDAY, 1900+$YEAR);
$CURR_HOUR = sprintf("%02d", $HOUR);
&traverse('e:/');
sub traverse {
local($dir) = shift;
local($path);
#print "$dir\n";
unless (opendir(DIR, $dir)) {
warn "Can't open $dir\n";
closedir(DIR);
return;
}
foreach (readdir(DIR)) {
next if $_ eq '.' || $_ eq '..' || ($_=~/perlscripts/i) ;
#Skip if these Dirs are found
$path = "$dir/$_";
if (-d $path) { # a directory
&traverse($path);
} elsif (-f _) { # a plain file
#print "$path\n"; # Print full path to display
$date_string = (stat($path)->mtime);
if ($now - $date_string < 3600) { # is file modified
in the last hour
$dest =$dir;
$dest =~ s/e:/D:\/Backups\/$DAY\/$CURR_HOUR\/Edrive/g;
#Strip out e: & subst i:
$dest1 = "$dest/$_";
# print "Backing up $path TO Hourly Backup Drive...\n";
mkpath ("$dest");
copy $path, $dest1;
}
}
}
closedir(DIR);
}
-----Original Message-----
From: Hanson, Robert [mailto:RHanson@APTEGRITY.com]
Sent: Tuesday, March 05, 2002 11:26 AM
To: 'Louden, Chris'; Beginners@perl. org (E-mail)
Subject: RE: finding example scripts
I think it is unlikely that you will find any samples on the web like this
(but ya never know).
Frankly though it sounds like a simple problem, maybe less than 10 lines of
code depending on the complexity. You might want to look at the docs for
File::Find and File::Copy to get some ideas.
http://search.cpan.org/doc/GSAR/perl-5.6.1-TRIAL3/lib/File/Find.pm
http://search.cpan.org/doc/ILYAZ/perl_mlb/File/Copy.pm
Rob
-----Original Message-----
From: Louden, Chris [mailto:LoudenCL@nv.doe.gov]
Sent: Tuesday, March 05, 2002 2:03 PM
To: Beginners@perl. org (E-mail)
Subject: finding example scripts
Anyone know any good site for example scripts, specifically for moving or
coping files that meet certain criteria?
Chris Louden
Engineering Automation Support
Bechtel Nevada / D.O.E.
702-295-2336 -phone
702-794-1968 -pager
click on the link below to send a text message to my pager:
http://paging.nv.doe.gov/gw.wwwMsgLookup?form_type=SPFP&pin_num=7027941968
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Thread Previous
|
Thread Next