update..I changed to use file:copy:recursive.. here is the code which works just fine.
use File::Copy::Recursive; use File::Find; use strict; my $srcdir='c:\\inetpub\\performancetesting\\output\\new\\'; my $destdir='c:\\'; File::Copy::Recursive::dircopy $srcdir, $destdir or die "Copy failed: +$!";
as part of a project I am working on I need to copy part of a directory tree to the root, this is to move files being processed by something else so that I can load them into a db. unfortunately its not working out yet, all i get is my warning can't open the file yet for each folder what stupid mistake am I making this time
use File::Copy; my $dir="c:\\inetpub\\performancetesting\\output\\new\\mlx\\"; my $dir2="c:\\"; lista_dirs($dir,$dir); sub lista_dirs{ my ($dir,$dirname)=@_; my (@dirs,@files); opendir DIR, "$dir"; my @dircontent=grep {/[^\.]/} readdir(DIR); closedir DIR; @dirs=(); @files=(); foreach(@dircontent){ if (-d "$dir/".$_){ push @dirs,$_; copy($dir,$dir2); } else { push @files,$_ if($_=~/\.txt$/); } } foreach my $d(@dirs){ lista_dirs("$dir/".$d,$d); print $d,"\n" ; #print $dir; prints full path? } }# not sure if this is going to work or not. opendir(IN,"$dir") or die "opening directory failed:$!"; while (defined (my $file = readdir(IN)) ) { push (my @files, $file); foreach my $filename (@files) { copy ("$dir".$filename, "$dir2".$filename) or warn "Can't open the fil +e yet $filename\n:$!"; } } closedir(IN);

In reply to attempt to copy files and directories to new location by grashoper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.