Check that file exists: Difference between revisions

(Added Toka)
Line 54:
==[[Pop11]]==
[[Category:Pop11]]
 
file_existssys_file_exists('input.txt') =>
file_existssys_file_exists('/input.txt') =>
file_existssys_file_exists('docs') =>
file_existssys_file_exists('/docs') =>
 
Note that the above literally checks for existence. Namely sys_file_exists
returns true if file exists but can not be read.
 
The only sure method to check if file can be read is to try to open it.
If one just want to check if file is readable the following may be usefull:
 
;;; Define an auxilary function, returns boolean
define file_existsfile_readable(fname);
lvars f = sysopen(fname, 0, true, `A`);
if f then
Line 65 ⟶ 76:
endif;
enddefine;
 
;;; Use it (prints true or false)
file_exists('input.txt') =>
file_exists('/input.txt') =>
file_exists('docs') =>
file_exists('/docs') =>
 
==[[DOS]]==
Anonymous user