Your script with those filenames works here:

in /testdir1/Results_2008:

12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_SU_A06_2008-12-01.ab1

in /testdir1/Results_2009: no files

My script:

#!/usr/bin/perl use warnings; use strict; my $topdir = "/home/zentara/testdir1"; my @subdirs = get_sub_dirs($topdir); my $newdir = "/home/zentara/testdir2"; 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; closedir $dh; return @dirs; } print "subdirs = @subdirs\n"; foreach my $dir(@subdirs){ opendir my $dh, "$topdir/$dir" or die "Error: $!"; my @files = readdir $dh; print "raw files = @files\n"; @files = grep /^(\d+\D\d)_(LacZ|pgK|SD|SU)(.*)$/,@files; print "$dir -> @files\n"; foreach my $file(@files){ # system( "mv $topdir/$dir/$file $newdir/$file"); } closedir $dh; }
OUTPUT:

subdirs = Results_2008 Results_2009

raw files = . .. 12774L1_SU_A06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1

Results_2008 -> 12774L1_SU_A06_2008-12-01.ab1 12774L1_pgK.Neo.2fw_D06_2008-12-01.ab1 12774L1_LacZ.SEE.rc_C06_2008-12-01.ab1 12774L1_SD_B06_2008-12-01.ab1

raw files = . .. Results_2009 ->

You must have some overlooked spelling error in your pathnames or something?


I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re^3: mv files from dir1 to dir2 by zentara
in thread mv files from dir1 to dir2 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.