mrityunjaynath has asked for the wisdom of the Perl Monks concerning the following question:

i am trying to code a perl script in which one of my objectives is to copy a source folder(which contains files and sub folders) to a target folder. what i have written is as

use strict; use warnings; use File::Copy; use File::Basename; use Cwd; use Data::Dumper; use File::Copy::Recursive; my $source_dirrtl = ("$newpath"."/rtl"); my $target_dirrtl1 = ("$newpath"."/rtl1"); mkdir($target_dirrtl1,0777); opendir(my $DIRRTL1, $source_dirrtl) || die "can't opendir $source_dir +rtl: $!"; my $cp = File::NCopy->new(recursive => 1); my $cp->copy("$source_dirrtl/*",$target_dirrtl1) or die "couldnt copy +$source_dirrtl to $target_dirrtl1);

each time i run this a error comes saying

Can't locate File/copy/recursive.pm in @INC <@INC contains C:/Perl/site/lib C:/Perl/lib .) at newperlfile2.pl line 9
BEGIN failed--compilation aborted at newperlfile2.pl line 9
please help as i am new to perl and struck in this error

Replies are listed 'Best First'.
Re: error in copy folder recursively
by Perlbotics (Archbishop) on Jul 04, 2015 at 08:38 UTC

    Seems that File::Copy::Recursive is not installed? However, you instantiate a new object ($cp) of type File::NCopy. If that is intentional, you should use that module instead.

    ... # use File::Copy::Recursive; # not used in your example use File::NCopy; # this is the module you're trying to +use later ...

      hii Perlbotics
      i have tried your suggestion but the error prevails only replacing File/copy/recursive.pm to File/Ncopy.pm
      how to install File::Ncopy then

        I'm not sure you understand what people and perl are telling you. The perl error means that File::Copy::Recursive is not installed. The module documentation explains how to install it. Use the cpan method so that dependencies are also installed.

        Later in your code you have:

        my $cp = File::NCopy->new(recursive => 1);

        Your code does not have a use line for this module, like you do have for the other modules.

        I wouldn't recommend manually moving modules around unless you understand what you are doing. In addition I would suggest you take a step back and review the code you've posted.

        Hello mrityunjaynath,

        No, stick with the File::Copy::Recursive module. File::NCopy is deprecated, according to its own documentation:

        File::NCopy - Deprecated module. Use File::Copy::Recursive instead.

        To learn how to install modules, see the Monastery’s Installing Modules tutorials. If you already have App::cpanminus installed, the process is as simple as entering:

        >cpanm File::Copy::Recursive

        from the command line.

        Another point: Where does $newpath come from? You need to declare and initialise it before it’s used:

        ... my $newpath = ...; # Provide an initial value here my $source_dirrtl = $newpath . "/rtl"; ...

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: error in copy folder recursively (missing module)
by Anonymous Monk on Jul 04, 2015 at 08:35 UTC
    How did you install File::Copy::Recursive? Because that error message is saying you didn't install File::Copy::Recursive
Re: error in copy folder recursively
by afoken (Chancellor) on Jul 04, 2015 at 19:12 UTC
    use strict; use warnings; use File::Copy; use File::Basename; use Cwd; use Data::Dumper; use File::Copy::Recursive; my $source_dirrtl = ("$newpath"."/rtl"); my $target_dirrtl1 = ("$newpath"."/rtl1"); mkdir($target_dirrtl1,0777); opendir(my $DIRRTL1, $source_dirrtl) || die "can't opendir $source_dir +rtl: $!"; my $cp = File::NCopy->new(recursive => 1); my $cp->copy("$source_dirrtl/*",$target_dirrtl1) or die "couldnt copy +$source_dirrtl to $target_dirrtl1);

    ...

    Can't locate File/copy/recursive.pm in @INC <@INC contains C:/Perl/site/lib C:/Perl/lib .) at newperlfile2.pl line 9

    There are at least three fishy things here:

    1. The usual error message uses "(" in front of the second @INC, but your error message has "<" there.
    2. The code you posted has use File::Copy::Recursive;, but the error message looks like the code was use File::copy::recursive;.
    3. The error message states that the problematic use is in line 9, but line 9 of your posted code is my $source_dirrtl = ("$newpath"."/rtl");. use File::Copy::Recursive; is in line 7.

    Please post the actual code and the actual error message. Don't type, use copy-and-paste!

    Also note that perl is case sensitive, even when Windows is not. There is a big difference between "use foo::bar;" and "use Foo::Bar;" for Perl, even if both load a file named "Foo/Bar.pm" from somewhere in your module search path (@INC). Always use the module name as it is documented in the module's documentation.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)