#!/usr/bin/perl use warnings; use strict; use POSIX qw(strftime); =for Will execute as a cronjob every evening @10PM. The "SequencingResults" dir is where the search will begin. The script will search subdirs based on the date. If the current date is " 01-16-09", then the path will be "SequencingResults/RESULTS 2009/JAN 2009/Results 01-16-09". If the first file has either LacZ|pgK|SD|SU then it will mv that file to $seqdir. It will do this recursively for each file. =cut my $topdir = "/home/mgavi/testdir1"; my @subdirs = get_sub_dirs($topdir); my $bottomdir = strftime "Results %m-%d-%y", localtime; # This keeps track of the current year my $yeardir = $year # This date will be passed readdir to get the current subdir my $date = strftime "%m-%d-%y", localtime; print "$date\n"; sub get_sub_dirs { my $dir = shift; opendir my $dh, $dir or die "Error: $!"; #print "$dh\n"; #this is your glob my @dirs = readdir $dh; #@dirs = grep /^Results(.*)$/,@dirs; @dirs = grep /^RESULTS(.*)$/,@dirs; closedir $dh; return @dirs; } print "subdirs = @subdirs\n"; foreach my $dir(@subdirs){ opendir my $dh, "$topdir/$dir" or die "Error: $!"; print $dh; my @files = readdir $dh; #print "raw files = @files\n"; @files = grep /^(\d+\D\d)_(LacZ|pgK|SD|SU)$/,@files; #print "$dir -> @files\n"; # create dir for raw seq files with permissions my $seqdir = "/home/mgavi/testdir2/SeqAssembly"; mkdir $seqdir, 0755; foreach my $file(@files){ system( "mv $topdir/$bottomdir/$dir/$file $seqdir/$fil +e"); } closedir $dh; }

Stdout is:
01-14-09
subdirs = RESULTS 2008 RESULTS 2009 RESULTS 2007
GLOB(0x804cd08)GLOB(0x804cd08)GLOB(0x804cd08)


None of the files are being moved to the new dir.


In reply to Re^4: How to use use the days date to read a dir? by lomSpace
in thread How to use use the days date to read a dir? by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.