splintor
splintor

Reputation: 10154

How do I clear the read-only flag from a file in Perl?

I need to clear the read-only flag of a file in my Perl program that runs on Windows.

I know system("attrib -r $filename") would work, but I was wondering if there is no built-in option in Perl to do it. chmod 777, $filename doesn't seem to work.

Thanks,

splintor

Upvotes: 11

Views: 6160

Answers (2)

cowgod
cowgod

Reputation: 8656

The most common way to handle this sort of thing is indeed with chmod. I was able to remove the read-only flag using the following with success:

chmod 0777, $filename;

This is using chmod's octal notation.

I'm using Strawberry Perl 5.8.8 on Windows Vista 64 bit.

Upvotes: 5

Sophie Alpert
Sophie Alpert

Reputation: 143194

Try chmod 0777, $filename. You need the permissions in octal notation.

Upvotes: 16

Related Questions