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

Re: How to copy and keep file permissions

Thread Previous | Thread Next
From:
zentara
Date:
February 17, 2002 11:43
Subject:
Re: How to copy and keep file permissions
Message ID:
en107ucsj0mu0rk3o185knu49crg6pl7gi@4ax.com
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
>problem.

>
>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
>ideas?

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

#!/usr/bin/perl
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About