[Israel.pm] File permissions and File::Copy

Offer Kaye oferk at oren.co.il
Mon May 31 08:25:00 PDT 2004


>
> Offer,
> I'm not sure on Linux but in windows you can "remember" the original
> permissions and set the copied file accordingly
>
> Regards,
> Dovalle
>

Of course! Thanks, I don't know why I didn't think of this method myself...
:-)
Yes, you can use Perl's "stat" function to remember the original
permissions - the 3rd element, "mode", is the file permissions. So now I
just do:

my $mode = (stat $from_f)[2];
copy($from_f,$to_f) or die "Couldn't copy $from_f to $to_f : $!\n";
chmod $mode, $to_f;

Thanks again Dovalle!

----------------------------------
Offer Kaye




More information about the Perl mailing list