I'm stumped, have tried a few different things (such as changing path names, creating dirs first, using "rename" instead of "move"), but I simply CANNOT get this script to work.
It does not die.
As is fairly obvious from the script, I am trying to move a bunch of mp3s (all in their own subdirs) to a new subdir.
Each list is contained in a file named mp3s
1-9.
For example "/home/ftp/pub/mp3/nin/nine_inch_nails_fixed_06_screaming_slave.mp3 to /home/ftp/pub/mp3/
mp3s7_dir/nin/nine_inch_nails_fixed_06_screaming_slave.mp3"
This is in preparation for a whole whack of backup-burning.
I can't see the problem
#!/usr/bin/perl -w
use strict;
use File::Copy; #rather than renaming
my $path = "/home/ftp/pub/mp3s/"; #just in case move needs a full path
chdir $path;
my @lists = <mp3s?>;
foreach (@lists){
open (FH, $_) || die "Could not read file :$!";
my $dir = $_ . "_dir";
mkdir $dir; #dir that we want to move the files into
while (<FH>){
chomp;
my $orig = $_;
s!/.*/(.*/.*)!$1!; #keep last dir + file name in new dir
my $dest = $path . $dir . "/" . $_;
move $orig,$dest ||
die "Could not move $orig to $dest: $!";
}
}
If I add a print right before the move, $orig and $dest print out correctly.
The dirs do get created properly, and the script does not die. This was a chunk of
a larger script that was going to move a chunk once size limit was reached, but because
of the problems I had, I moved this portion to this script.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.