in reply to Re^4: Processing data in on dir and copying, then processing into another dir
in thread Processing data in on dir and copying, then processing into another dir

Yeah, you have path issues, and possibly regex issues. mv requires full path names. The following works. In testdir1 I have 2 subdirs Results_2008 and Results_2009. In those subdirs , I have files:
Results_2008: 2008_12112L5_LacZ 2008_12112L5_pgK 2008_12112L5_SD 2008_12112L5_SU Results_2009: 2009_12112L5_LacZ 2009_12112L5_pgK 2009_12112L5_SD 2009_12112L5_SU
this script moves them all, and notice the regex(probably can be improved) and full path in the system mv
#!/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]+_[\dL]+_(LacZ|pgK|SD|SU)(.*)$/,@files; print "$dir -> @files\n"; foreach my $file(@files){ system( "mv $topdir/$dir/$file $newdir/$file"); } closedir $dh; }
Also remember, if you want to separate your files out into subdirs, you need to make the subdirs first, before trying to mv them there. See cloning a directory tree

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

Replies are listed 'Best First'.
Re^6: Processing data in on dir and copying, then processing into another dir
by lomSpace (Scribe) on Jan 12, 2009 at 02:19 UTC
    My first step is to get the files in Results 2009 that match the regex to mv to a new dir. Next, in the new dir I want to match all the file with dir that have the same id number.
    Ex. 2009_12112L5_LacZ 2009_12112L5_pgK 2009_12112L5_SD 2009_12112L5_SU >
    12112, so each of the files will go into a new dir called 12112/12112_sa.
    I think a hash should help me with the matching. Much Thanks!
Re^6: Processing data in on dir and copying, then processing into another dir
by lomSpace (Scribe) on Jan 12, 2009 at 02:43 UTC
    Did I mention that OS is Unix? Also after testing the code it returns:

    GLOB(0x804cbdc)
    . .. RESULTS 2008 RESULTS 2009 RESULTS 2007
    subdirs =
    nothing is mv to newdir