The file-writable-p docstring says:
Return t if file FILENAME can be written or created by you.
In Windows you cannot usually write on files when they are used by a different app. In these instances you get a permission denied error since the process blocks the access.
For example, in most of the viewers, if you open ~/foo.pdf, you cannot write access to it. However:
(file-writable-p "~/foo.pdf") still returns t. Therefore, with ~/foo.pdf open,
(if (file-writable-p "~/foo.pdf") (with-temp-file "~/foo.pdf" (insert "Hello World"))) returns the error: (file-error "Opening output file" "Permission denied" ..... The same happens with:
(if (file-writable-p "~/foo.pdf") (delete-file "~/foo.pdf")) Is this the way file-writable-p is intended to work?
If so, which is the proper path to safely write some output to a file?
x) permissions on the directory where the file is. You typically need that.file-writable-por an equivalent Emacs file system function.