A function that can be used in Scripting.

Syntax and semantics

tryToWriteFile (filePath$)
check whether this file can be written to.

The file is opened for writing, then closed (if the file already existed, it is emptied!).

Return value

Upon success (i.e. the file already existed and was successfully emptied, or the file didn’t exist yet but was successfully created), this function returns 1 (true). Otherwise, the function returns 0 (false); this can happen if the folder in the path does not exist, or if the file is (or would be) on a read-only device.

For instance, if my TIMIT database is in a read-only disk image called TIMIT.dmg, and I mounted that disk image on my Mac (by double-clicking TIMIT.dmg), then trying

    tryToWriteFile ("/Volumes/TIMIT/hello.txt")

would return 0.

Related function

For a non-destructive version of this function, see tryToAppendFile.

Links to this page

© Paul Boersma 2023