lomSpace has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks!
I am developing a script that will work as a cron job.
When I hard code the path where the files are located
it works fine.
/home/lomSpace/testdir1/RESULTS 2009/JAN 2009The problem is that it needs to work this year
use Time::localtime; and use POSIX qw(strftime);to deal with the issue of the subdir names. So the script
#!/usr/bin/perl use warnings; use strict; use File::stat; use Time::localtime; use File::Copy; use File::Find; use POSIX qw(strftime); #=for my $tm = localtime; my $YEAR= $tm->year+1900; my $MONTH = $tm->mon; #my $subdir = strftime "Results %m-%d-%y", localtime; #my $YEAR=year+1900; #my $MONTH = #my $YR_RESULT_dir = strftime "RESULTS $YEAR", localtime; #my $Month_YR_dir = strftime "$MONTH $YEAR", localtime; my $root='/home/lomSpace/testdir1'; my $seqdir = "/home/lomSpace/testdir2/SeqAssembly"; print "$YEAR $MONTH $root\n"; opendir (my $dh, $root); my @files=readdir $dh; for my $f (@files){ my $mod_time=-M $root."/".$f; #skip unless modification date is less than one day ago next if $f eq '.' || $f eq '..' || $mod_time > 1.0; print $f,"\t",$mod_time,"\t",ctime(stat($root."/".$f)->mtime),"\n" +; copy("$f","$seqdir"); } closedir $dh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically searching subdirs with titles based on year,month, and date
by johngg (Canon) on Jan 16, 2009 at 22:54 UTC | |
|
Re: Dynamically searching subdirs with titles based on year,month, and date
by JavaFan (Canon) on Jan 16, 2009 at 21:56 UTC | |
by lomSpace (Scribe) on Jan 16, 2009 at 23:13 UTC | |
by JavaFan (Canon) on Jan 16, 2009 at 23:37 UTC | |
by hbm (Hermit) on Jan 16, 2009 at 23:59 UTC | |
by lomSpace (Scribe) on Jan 20, 2009 at 16:24 UTC | |
by lomSpace (Scribe) on Jan 20, 2009 at 17:47 UTC |