ofer
ofer

Reputation: 535

Overwrite read-only file with the Perl File::Copy function

I need to copy read-only files in Perl. I tried using Perl::Copy function, but it fails in case the file already exists and isn't writable.

Is there a force argument I can give to the copy function?

I want to avoid changing permissions of files, or removing the destination file before copying.

Upvotes: 2

Views: 4622

Answers (3)

Lucien
Lucien

Reputation: 451

To complete the Ron answer, the Perl documentation says :

copy will not overwrite read-only files.

That's why we need to change permissions or delete file before copy.

Upvotes: 0

Rahul Juyal
Rahul Juyal

Reputation: 2144

with out changing permission you can't overwrite the file.in perl no function for force fully you overwrite

Upvotes: 0

e.dan
e.dan

Reputation: 7497

Seems like you are giving yourself unreasonable requirements. I think the best solution is to remove the destination file before copying, which should be as simple as:

unlink $dest_file if -e $dest_file;

Upvotes: 4

Related Questions