in reply to Trying to find and copy mp3s
It's a bad idea to use $_ for two loops at once. I don't think that's what your problem is here, but it could become a maintainability problem later.
You should check that chdir and copy succeeded before charging ahead in your loop (as already suggested by Joost).
It's always a good idea to use warnings too (though, again, I don't think that will help in this case). [Oops, as esper points out, the OP already has -w.]
#!/usr/bin/perl -w #mp3Finder.pl use strict; use warnings; use File::Copy; foreach my $dirnum (1 .. 262) { print $dirnum; my $dir = "/media/second/testdisk/linux/recup_dir.$dirnum"; print $dir; chdir($dir) or die "Can't chdir($dir): $!"; my @mp3s = glob "*.mp3"; foreach my $mp3 (@mp3s) { my $music = "/home/zack/music/$mp3"; copy($mp3, $music) or die "Can't copy $mp3 to $music: $!"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to find and copy mp3s
by Anonymous Monk on Feb 12, 2007 at 00:55 UTC | |
by kyle (Abbot) on Feb 12, 2007 at 02:07 UTC | |
|
Re^2: Trying to find and copy mp3s
by dsheroh (Monsignor) on Feb 12, 2007 at 15:48 UTC | |
by davorg (Chancellor) on Feb 12, 2007 at 16:17 UTC | |
by kyle (Abbot) on Feb 12, 2007 at 15:53 UTC | |
by dsheroh (Monsignor) on Feb 12, 2007 at 16:05 UTC | |
by MidLifeXis (Monsignor) on Feb 12, 2007 at 18:48 UTC |