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;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.