Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I test if a file has write permission?

by fx (Pilgrim)
on Dec 19, 2003 at 23:35 UTC ( #315951=note: print w/replies, xml ) Need Help??


in reply to How do I test if a file has write permission?

Another, but probably less efficient way, is to open the file in append mode. If the open fails the file COULD be read-only:

open(FILE, ">>some_file.txt") || print "File is read only";

The advantage of this way, I suppose, is that if you really want to write things to the end of the file then it's now open :)

Replies are listed 'Best First'.
Re: Answer: How do I test if a file has write permission?
by exussum0 (Vicar) on Dec 20, 2003 at 20:58 UTC
    Open fails when it can't write, period. So if a directory where a file is expected or you have an NFS timeout, this will fail for non-permission reasons.

    (Why would your current directory be missing? If someone else rm's it of course :)


    Play that funky music white boy..

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://315951]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2021-04-18 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?