Version 4 of file writable

Updated 2007-07-25 22:01:13 by EL

file writable name

Returns 1 if file name is writable by the current user, 0 otherwise.


RS just noticed that from Windows 2000 over network boundaries, it may report 1 even for directories where I positively may not write. A hacky workaround seems to be:

 set dummyname $name.[clock seconds] ;# not to clobber an existing one
 if { [catch {file open $dummyname w]} fp] } {
   # not writable
 } else {
   close $fp
   file delete $dummyname
 }

EL I confirms this, and regrettably notice that the converse is also true: 0 is being returned where I do have permission to write. I'd even extend Richard's hack to:

 rename file _file
 proc file {args} {
     if {[lindex $args 1] eq "writable"} {
         set dirName [lindex $args 2]
         if {[file isdir $dirName]} {
             set fileName [file join $dirName dummy.[clock seconds]]
             if {[catch {open $fileName w} fp]} {
                 # not writable
                 return 0
             } else {
                 close $fp
                 file delete $fileName
                 return 1
             }
         } else {
             eval _file $args
         }
     } else {
         eval _file $args
     }
 }

Vince adds --- 'NativeAccess' in tclWinFile.c needs updating to deal with Windows user/permission-related information (whatever that is -- anyone have any pointers?).

EL would TWAPI be of use here?


See also:


Tcl syntax help - Category Command - Category Introspection - Category File