Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How do I test whether or not a file is writable?

by Anonymous Monk
on Apr 20, 2000 at 21:57 UTC ( [id://8221]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I test whether or not a file is writable?

Originally posted as a Categorized Question.

  • Comment on How do I test whether or not a file is writable?

Replies are listed 'Best First'.
Re: How do I test whether or not a file is writable?
by chromatic (Archbishop) on Apr 20, 2000 at 22:05 UTC
    The -w test will do:
    if (-w FILEHANDLE) { print "It's writeable by my effective uid or gid!\n"; }
    For more information, see -X (or perldoc -f -X).
Re: How do I test whether or not a file is writable?
by kiruthika.bkite (Scribe) on Mar 18, 2010 at 10:56 UTC
    if(-f $name ) { if(!(-w $name)) { print "File '$name' doesn't have write permission\n"; } }

    -f switch is used to check whether $name is file or not.
    -w switch is used to test whether file has write permission or not.
      There's no point testing for both -f and -w. If the file doesn't exists (or if its existence cannot be determined), -w will return false. And if -w returns true, the file exists.
        Yes, but -w would also return true if the file is actually a writeable directory
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found