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: $!"; } }

In reply to Re: Trying to find and copy mp3s by kyle
in thread Trying to find and copy mp3s by HeyYou

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.