grashoper has asked for the wisdom of the Perl Monks concerning the following question:
I finally managed to move my files. posting the code.
this is dependent on being in the correct path of the sourcetree when it is ran, it will recurse directories grabbing text files and move them to the directory specified in $dir2.
however something odd happens if there are no txt files,
I get this as output.
Output when there are no files within subdirectories in move.pl
actually it doesn't seem to matter whether ther are files or not, what have I done, it worked yesterday today its toast and my deadline is tomorrow :(
./Documents and Settings/aanderso/Local Settings/Application Data/Microsoft/Inte
rnet Explorer
brndlog.txt
this is c:\mlx\
this would be c:\mlx\./Documents and Settings/aanderso/Local Settings/Applicatio
n Data/Microsoft/Internet Explorer
this should be c:\mlx\/./Documents and Settings/aanderso/Local Settings/Applicat
ion Data/Microsoft/Internet Explorer/brndlog.txt
do you see the problem yet?
Unable to move No such file or directory at c:\inetpub\performancetesting\output
\new\1.pl line 66.
use DirHandle; use File::Find; use File::Copy; use Data::Dumper; use strict; use warnings; my $dir= "."; my $dir2="c:\\mlx\\"; lista_dirs($dir,$dir); #lista_dirs2($dir2,$dir2); sub lista_dirs{ my ($dir, $dirname) = @_; my (@dirs, @files); opendir DIR, "$dir"; my @dircontent = grep { /[^\.]/ } readdir(DIR); closedir DIR; # opendir DIR2, "$dir2"; #my @dircontent2 = grep { /[^\.]/ } readdir(DIR); #closedir DIR2; # @dirs2=(); #@files2=(); @dirs = (); @files = (); foreach(@dircontent) { if(-d "$dir/".$_) { push @dirs, $_; } else { push @files, $_ if($_ =~ /\.txt$/); } } #foreach(@dircontent2){ #if(-d "$dir2/".$_) { #push @dirs2, $_; #} else { # push @files2, $_ if($_ =~ /\.txt$/); #} #} foreach my $d(@dirs) { lista_dirs("$dir/" .$d, $d); } foreach my $file (@files) { $/ = ''; print $dir, "\n"; print $file, "\n"; print "this is $dir2 \n"; print "this would be $dir2$dir \n"; print "this should be $dir2/$dir/$file \n"; print "do you see the problem yet? \n"; move ("$dir/$file","$dir2/$dir/$file") or die "Unable to move $!"; } return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: move files revisited
by ramrod (Curate) on Apr 29, 2009 at 17:57 UTC | |
Re[2]: move files revisited
by tokpela (Chaplain) on May 01, 2009 at 08:36 UTC |
Back to
Seekers of Perl Wisdom