Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Anonymous Monk
on Apr 20, 2000 at 21:57 UTC ( #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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-04-21 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?