Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

help needed in File::copy

by uva (Sexton)
on Mar 01, 2006 at 11:30 UTC ( [id://533622]=perlquestion: print w/replies, xml ) Need Help??

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

dear monks , i tried the following statement inorder to copy from file1 to tmp. first time it copied . when i tried for second time it is giving the error. copy("file1", "tmp"); does the above statement will work without giving any error if "temp" file is already existing with data. since it is giving error for me as "cant open "tmp" file "

Replies are listed 'Best First'.
Re: help needed in File::copy
by mickeyn (Priest) on Mar 01, 2006 at 11:59 UTC
    I didn't test it, but the destination file opening line in that module is:
    open($to_h,"> $to\0") or goto fail_open2;
    so it should override the file ...

    Enjoy,
    Mickey

      dear monks, copy("c:\\dir1\\text.errmsg", "c:\\dir2\\text.errmsg") || die "Can't open text.errmsg:$!"; when i ran the program, it creates the file and copied the content. next time i ran the program (destination file is existing now ) it is giving error message. Normally it should overwrite it ,but it is not happening here.. can u explain in detail??

        copy will check if the destination file exists. I don't think exists a parameter for overwrite destination file. Maybe you want this:

        unlink $destfile if -f $destfile; copy($origfile, $destfile);

        Update: This is a workaround. As mickeyn said at Re: help needed in File::copy, File::Copy should overwrite destination file.

        Igor 'izut' Sutton
        your code, your rules.

Re: help needed in File::copy
by CountOrlok (Friar) on Mar 01, 2006 at 17:14 UTC
    If I understand properly, you should check the file permissions after it got created the first time. It is probably set to read-only for user.
    See the umask function for details.

    -imran

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://533622]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2025-01-13 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (32 votes). Check out past polls.