nu2thegame has asked for the wisdom of the Perl Monks concerning the following question:
Hello... Perl lovers (one of which I am seeking to be)....I have the following script but it is returning errors..Here is the script:
use strict; use warnings; use File::Copy 'move'; # Determine destination folder for file based on filename. # All destinations are below a fallback destination provided as input. sub make_dest_finder { my $fallback_dest = shift; return sub { my $fnam = shift; # Determine basename to start looking for a destination folder +. my $basename = substr $fnam, 0, rindex $fnam, '.'; # Shorten name while no homonymous folder exists. chop $basename while $basename && ! -d "$fallback_dest/$basena +me"; return "$fallback_dest/$basename" if $basename; return $fallback_dest; }; } my $srcdir = "/tmp/folder"; my $dest_finder = make_dest_finder '/tmp/folder2'; opendir my $dh, $srcdir or die "Can't open $srcdir: $!"; my @files = grep ! /^\.+$/, readdir $dh; close $dh; my $moved = 0; foreach my $file (@files) { my $old = "$srcdir/$file"; my $dest = $dest_finder->( $file ); print STDERR "moving $file to $dest\n"; if ( ! move $old, $dest ) { warn "Move $old -> $dest failed: $!"; last; } $moved++; } print STDERR "\n\n- moved $moved files\n";
The error states that "Can't open /tmp/folder: Not a directory at movingfilesscript.pl line 23" Can anyone please help a newbie... And let me apologize if this is not the right forum or if in some way, I have disrespect the rules of the forum... This is literally my first post ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help diagnosing an error opening a directory
by MidLifeXis (Monsignor) on Oct 31, 2012 at 15:41 UTC | |
|
Re: From a Newbie/help diagnosing an error opening a directory
by Kenosis (Priest) on Oct 31, 2012 at 15:46 UTC | |
|
Re: From a Newbie/help diagnosing an error opening a directory
by tobyink (Canon) on Oct 31, 2012 at 16:04 UTC |