Solved

PERL Copy command not working for me

Posted on 2009-04-10
5
963 Views
Last Modified: 2012-05-06
I am trying to copy one file from one directory to another..

use File::Copy;

use File::Path;

copy("begperl/MODE3.txt","BASELINE/MODE4.txt"); but for some reason it's not calling an error and it is not copying the file either :'( i also tried this:
 

sub copy

{ my($from, $to) = @_;

  if(open(IN, $from))

  {  if(open(OUT, ">$to"))

     {  while(read IN, $buf, 4096)

        {   print OUT $buf;

        }

        close IN;

        close OUT;

        }

     close IN;

  }

}
 

&copy("/begperl/MODE3.txt","/BASELINE/MODE4.txt");
 

and nothing :'( do you know where my mistake could be? thankssssssss :) you're awesome :)

Open in new window

0
Comment
Question by:cucugirl
5 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24118842
You should display the error when it doesn't succeed:
    copy("begperl/MODE3.txt","BASELINE/MODE4.txt") or die "Could not copy: $!\n";

Or when you open:
    if(open(IN, $from)) {
       ...
    }
    else {
        die "Could not open input: $!\n";
    }

0
 

Author Comment

by:cucugirl
ID: 24118897
Could not copy: No such file or directory
it's weird though because the file exists.. M:\begperl and M:\BASELINE
im trying to copy the file from begperl to BASELINE

thanks! for that tip :)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24119444
That file may exist, but you have specified a relative path rather than an absolute path.

Use

copy "M:/begperl/MODE3.txt","M:/BASELINE/MODE4.txt" or die "Could not copy MODE3.txt because $!\n";
0
 
LVL 13

Expert Comment

by:marchent
ID: 24172108
Use the windows copy command directly using function system();

system("copy M:/begperl/MODE3.txt M:/BASELINE/MODE4.txt");
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 125 total points
ID: 24172293
marchent>>Use the windows copy command directly using function system()

Doing this, you don't know if the command is successful.  It'd be better to fail and know it than to fail and not know it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now