On May 25, 1:30 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On May 23, 9:59 am, Alma <[EMAIL PROTECTED]> wrote: > > > > > On May 23, 7:28 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > wrote: > > > > On May 23, 8:14 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > > wrote: > > > > > On May 23, 7:47 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > > > > wrote: > > > > > > On May 23, 5:13 am, Alma <[EMAIL PROTECTED]> wrote: > > > > > > > Hi All, > > > > > > > I have tocreatea script that creates adirectoryon day basis & > > > > > > need to store the files uploaded on that particular day to that > > > > > >directory. > > > > > > > Any help regarding it will be appreciated . > > > > > > > alma > > > > > > #!/usr/bin/perl -w > > > > > > use strict; > > > > > use File::Find; > > > > > use File::Copy; > > > > > use Time::Local; > > > > > > my($day, $mon, $yr) = (localtime)[3, 4, 5]; > > > > > my $dir = $day . "_" . ($mon + 1) . "_" . ($yr + 1900); # check epoch > > > > > if you are going to use date as dir name (UNIX $yr + 30 i think) > > > > > > mkdir "$dir"; > > > > > print "directorycreated: $dir\n"; > > > > > > my $start = timelocal(0, 0, 0, $day, $mon, $yr); # midnight > > > > > today > > > > > my $stop = $start + (24 * 60 * 60 ) - 1; > > > > > > sub find_uploads_today{ > > > > > my $start = shift; > > > > > my $stop = shift; > > > > > my @files; > > > > > > return ( > > > > > sub{ > > > > > my $timestamp = (stat $_)[9]; > > > > > push @files, $_ if $timestamp > $start && > > > > > $timestamp < $stop && - > > > > > f; > > > > > }, > > > > > sub{ > > > > > return @files; > > > > > } > > > > > ); > > > > > > } > > > > > > my($gather, $yield) = find_uploads_today($start, $stop); > > > > > find($gather, "."); > > > > > my @files = $yield->(); # contains only files that are uploaded today > > > > > > foreach (@files) > > > > > { > > > > > if ($_ ne $0){ # ensuring that if script in same dir as > > > > > uploads it is > > > > > not moved to day folder > > > > > move("$_", "$dir/$_") or die "move failed: $!"; # 2nd > > > > > param is > > > > > system specific - change if using Windows > > > > > print "moving $_\n"; > > > > > } > > > > > > } > > > > > you can cut these lines and place them in the sub in place of $start = > > > > shift and $stop = shift: > > > > my $start = timelocal(0, 0, 0, $day, $mon, $yr); # midnight > > > > today > > > > my $stop = $start + (24 * 60 * 60 ) - 1; > > > > you could also replace the foreach loop at the bottom with: > > > > grep { > > > if ($_ ne $0){ > > > move("$_", "$dir/$_") or die "$!"; > > > print "moving $_\n"; > > > } > > > > } @files; > > > Thanks a lot. > > > Can i keep the perl scrip to create a directory in cron.daily. so that > > it gets created & while storing the files in the date folder. it > > checks for the today's date & store it . > > Do you want all the uploaded files copied to the same main directory > (moved_uploads) but separated by date? > +some_folder > +moved_uploads > |-24_May_2007 > |-25_May_2007
yes a sort of i wanted tot keep the main folder as backup. for ex. /home/project/backup/$_today's_dir(Which should be date) & dump all the files uploaded today . for tommorow another folder should get created in the location /home/project/backup/$tommorow_dir .. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/