On 3 Jan 2007 at 16:19, Tom Messmer wrote: Hi Tom,
They like you to bottom post of this list. See below. > instead of > Copying /usr/blah/htdocs/media/events/blah06/epic_struggle/mp3/ > cuchailain.mp3-> /home/messmer/test/fake_mp3dir/cuchailain/ > cuchailain.mp3 > > In other words, there will be a directory full of mp3s like: > /usr/whatever/cuchailain.mp3 > /usr/whatever/ulysses.mp3 > /usr/whatever/beowulf.mp3 > /usr/whatever/Sigurðr,mp3 (Ok, i'd need unicode for that one, never > mind...) > > and I want to copy them into already existing directories like > /home/messmer/mp3s/cuchailain/ > /home/messmer/mp3s/ulysses/ > /home/messmer/mp3s/beowulf/ > > > Maybe I missed some nuance of your script that would have done > this...? I'm just starting out with perl really so please excuse my > ignorance. ...snip > > #!/usr/bin/perl # or where ever your perl is installed. > > > > use strict; > > use warnings; > > use File::Copy; > > use File::Basename; # Not needed. > > > > my $source_dir = '/usr/blah'; > > my $distin_dir = '/usr/blany/blanagain/'; > > > > # Open the dir for reading or die. > > opendir(DIR,$source_dir) or die "Can't open $source_dir: $!\n"; > > > > # Collect the author directories (and names). > > my @auth_dir = grep { -f "$source_dir/$_" } readdir(DIR); > > > > foreach my $i (@auth_dir) { > > > > # Get the filename of the file from /usr/blab/flynn.foo > > my $pathname = "$source_dir/$i"; okay I think I see what you want. I have changed it a bit. my @f = split(/\./,$i); # make the path to the author directory. my $author_dir = $distin_dir.$f[0]; # Check the author's dir exists, if not make it. if (! -e $author_dir) { print "making $author_dir\n"; # mkdir("$author_dir") or die "Can't make $author_dir: $!\n"; } my $newname = $author_dir.'/'.$f[1]; print "Copying $pathname-> $newname\n"; # Keep commented until your sure. # copy($i, $newname) or die "Can't copy $i -> $newname: $!\n"; } print "Done...\n"; I have over-elabroated on the variables for clarity. Better perlers then me will be able show you some optimisations. Essentially all the hard work is done by split which will breaks the filename into two strings between the period ($f[0]=cuchailain $f[1]=mp3) . If your filename's have more then one dot/period, you'll need to use another technique. perldoc -f split # for info on split perldoc -f -X #' for info on file tests HTH, Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/