KumaSan
05-27-2002, 11:45 PM
Okay, as part of my attempt at learning perl, I'm writing small program that will move my ogg's from my old hard drive (mounted on /mnt/mp3) to my new one (mounted at /mp3). As a complete newbie, I'm having trouble with even this small task. Here's the relevant code:
#!/usr/bin/perl -w
use File::Copy;
$dir = $ARGV[0];
$dir2 = $ARGV[1];
foreach (`ls $dir`) {
chomp;
$name = $_;
if (-d $name) {
mkdir "$dir2/$name";
}
else {
copy("$dir/$name", "$dir2/$name");
}
}
As you can see, it's still way unfinished (doesn't go into the subdirectories for one thing...) but I'm having big problems with the -d file test. Nothing matches on this. Is there something wrong with my foreach statement? I know there are easier ways to do this (cp at a command line comes to mind) but since I just started learning perl, I need to practice it.
Anyway, thanks in advance for the help. Be gentle, I've only been coding for about 2 weeks.
#!/usr/bin/perl -w
use File::Copy;
$dir = $ARGV[0];
$dir2 = $ARGV[1];
foreach (`ls $dir`) {
chomp;
$name = $_;
if (-d $name) {
mkdir "$dir2/$name";
}
else {
copy("$dir/$name", "$dir2/$name");
}
}
As you can see, it's still way unfinished (doesn't go into the subdirectories for one thing...) but I'm having big problems with the -d file test. Nothing matches on this. Is there something wrong with my foreach statement? I know there are easier ways to do this (cp at a command line comes to mind) but since I just started learning perl, I need to practice it.
Anyway, thanks in advance for the help. Be gentle, I've only been coding for about 2 weeks.