write enable test function

Started by heartbone, October 13, 2003, 02:13:28 PM

Previous topic - Next topic

heartbone

As you know DarkBASIC can not trap disc write errors,
i.e. trying to write to a file that is locked will crash the app.

If you want to distribute software which saves files into the execution folder, it may be wise to call this function at the top of your code so you can switch off or redirect the file saving if it returns 0.  This way you can distribute you app on CD and folks could run it off the CD without it failing.


Function WRITEST()
Rem  Returns 1 if current folder (execution directory) can be written to
  CAN_SAVE= 0
  If File Exist("savetest") Then Delete File "savetest"
  Open To Write 1,"savetest"
  Close File 1
  Wait 800
  If File Exist("savetest") Then CAN_SAVE= 1 : Delete File "savetest"
Endfunction CAN_SAVE