copying files or a directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanponnapalli
    New Member
    • May 2008
    • 51

    copying files or a directory

    hi,
    I have got a list of files in a "list" as follows:
    [code=perl]
    foreach(@arr)
    {
    copy ("$_", "/home/pavan/tmp") or die "copy failed: $! ";
    }
    [/code]
    The path where the files are stored is /home/pavan/perl.
    I need to copy all the files in perl directory to the temporary directory
    "tmp" as in the copy statement. For that i used a package File::Copy.
    I am able to print the files with print "$_ \n";
    But unfortunately the copy statement is not working . I am not getting an error either.
    So could u tell me how to copy all the files in perl to tmp directory? Also is there any method to copy the perl directory as a whole to tmp directory?

    Thanks & Regards,
    pavan.
    Last edited by numberwhun; Jun 17 '08, 01:00 PM. Reason: Please use code tags!
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    You say you can print the file names with the print statement, but does the file names include the full path? If you are executing the script from somewhere other than the directory where all of the files are located, then you will need to include the full path with something like this:

    [code=perl]
    foreach(@arr)
    {
    copy ("/home/pavan/perl/$_", "/home/pavan/tmp") or die "copy failed: $! ";
    }
    [/code]

    Oh, and please use code tags next time when including code.

    Regards,

    Jeff

    Comment

    • pavanponnapalli
      New Member
      • May 2008
      • 51

      #3
      hi ,
      all the files which i like to copy in /tmp directory are in the directory /perl itself . so i used $_ directly without giving full path . I also tried the way just u have told me . I had given the full path. But it has not worked . Also there is no error. So, is there any alternative to do the above work?

      Thanks & Regards,
      pavan

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by pavanponnapalli
        hi,
        I have got a list of files in a "list" as follows:
        [code=perl]
        foreach(@arr)
        {
        copy ("$_", "/home/pavan/tmp") or die "copy failed: $! ";
        }
        [/code]
        The path where the files are stored is /home/pavan/perl.
        I need to copy all the files in perl directory to the temporary directory
        "tmp" as in the copy statement. For that i used a package File::Copy.
        I am able to print the files with print "$_ \n";
        But unfortunately the copy statement is not working . I am not getting an error either.
        So could u tell me how to copy all the files in perl to tmp directory? Also is there any method to copy the perl directory as a whole to tmp directory?

        Thanks & Regards,
        pavan.

        I think the problem is you are copying all the files in the perl directory to the pavan directory into a file named tmp.

        Assuming you are in the directory where the files are to be copied from:

        [code=perl]
        foreach(@arr)
        {
        copy ("$_", "/home/pavan/tmp/$_") or die "copy failed: $! ";
        }
        [/code]

        copy() takes two arguments, a file to copy from and a file to copy to.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by KevinADC
          I think the problem is you are copying all the files in the perl directory to the pavan directory into a file named tmp.

          Assuming you are in the directory where the files are to be copied from:

          [code=perl]
          foreach(@arr)
          {
          copy ("$_", "/home/pavan/tmp/$_") or die "copy failed: $! ";
          }
          [/code]

          copy() takes two arguments, a file to copy from and a file to copy to.
          Ouch! I completely missed the lacking "/" that was missing after the "tmp" dir name. C'est la vie.

          Jeff

          Comment

          • pavanponnapalli
            New Member
            • May 2008
            • 51

            #6
            Originally posted by numberwhun
            Ouch! I completely missed the lacking "/" that was missing after the "tmp" dir name. C'est la vie.

            Jeff
            hi,
            i think the files are not copying bcoz tmp is a directory in which system generated temporary files are stored? Can we copy files into a directory which contains system generated files?

            Comment

            Working...