in reply to Re^2: mv files from dir1 to dir2
in thread mv files from dir1 to dir2

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

Replies are listed 'Best First'.
Re^4: mv files from dir1 to dir2
by lomSpace (Scribe) on Jan 12, 2009 at 19:11 UTC
    Thanks for the help with getting the "glob".
    Duh! on my part. Now that I can see the dirs that I want to
    search. I need to look into the subdir to see if I want to move it to testdir2.
    So the first file in each dir that I want to mv to testdir2 will be similar
    to:
    12635L1_LacZ.SEE.rc_G03_2008-12-01.ab1
    12635L1_pgK.Neo.2fw_H03_2008-12-01.ab1
    12635L1_SD_F03_2008-12-01.ab1
    12635L1_SU_E03_2008-12-01.ab1 The dir could start with anyone of them based on the regex. This is a unique file naming convention.
    Now that I have the $topdir should I do another foreach to read through the dirs?
      We showed you enough tricks, so that you should be able to work it out by hacking on your own. Just add alot of print statements to debug what are your dirs, files and pathnames, and you will eventually get it they way you want. Just pay attention to detail.

      I'm not really a human, but I play one on earth Remember How Lucky You Are
        Cool!
Re^4: mv files from dir1 to dir2
by lomSpace (Scribe) on Jan 12, 2009 at 19:23 UTC
    I need to peek into these subdirs to determine is I will mv to testdir2:
    Results 12-01-08A Results 12-05-08C Results 12-15-08C Results 12-18 +-08D Results 12-01-08B Results 12-08-08A Results 12-15-08D Results 12-19 +-08A Results 12-01-08C Results 12-08-08B Results 12-15-08E Results 12-19 +-08B Results 12-01-08D Results 12-08-08C Results 12-15-08F Results 12-19 +-08C Results 12-02-08A Results 12-09-08A Results 12-15-08G Results 12-19 +-08D Results 12-02-08B Results 12-09-08B Results 12-15-08H Results 12-22 +-08A Results 12-02-08C Results 12-10-08A Results 12-16-08A Results 12-22 +-08B Results 12-03-08A Results 12-10-08B Results 12-16-08B Results 12-23 +-08A Results 12-03-08B Results 12-10-08C Results 12-17-08A Results 12-23 +-08B Results 12-04-08A Results 12-11-08A Results 12-17-08B Results 12-23 +-08C Results 12-04-08B Results 12-11-08B Results 12-18-08A Results 12-05-08A Results 12-15-08A Results 12-18-08B Results 12-05-08B Results 12-15-08B Results 12-18-08C