develooper Front page | perl.beginners | Postings from February 2002

Re: How to copy and keep file permissions

Thread Previous | Thread Next
February 17, 2002 11:43
Re: How to copy and keep file permissions
Message ID:
On Sat, 16 Feb 2002 20:23:02 +0000, cemberly@UU.NET (Craig Eberly) wrote:

>Hey, any help would be appreciated.
>I just wanted to make a simple backup script to backup any file i
>specified quickly.. and eventually let it accept options and whatnot for
>directories, but right now, I'm just trying to get it to keep the file
>permissions of the original file.  I'm using File::Copy for the
>copying,  and I thought Digest::MD5 would work for the permissions

>The backup itself works like this,  but the # lines are what i was
>trying to do to keep the file permissions.  This not only doesnt work,
>but it causes the backup process to break as well.  Anyone have any

Here, this shows you the basics of retaining file permissions.

use warnings;
use File::Copy;
use strict;
my $mode = (stat $ARGV[0])[2];
copy( "$ARGV[0]", "$ARGV[0]\.bak" );
chmod ($mode, "$ARGV[0]\.bak");
print "Backup completed.\n";
exit 0;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About