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
this script moves them all, and notice the regex(probably can be improved) and full path in the system mvResults_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
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#!/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; }
|
|---|
| 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 | |
|
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 |