Jump to content

Check that file exists: Difference between revisions

No edit summary
Line 97:
}</lang>
 
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f CHECK_THAT_FILE_EXISTS.AWK
BEGIN {
check_exists("input.txt")
check_exists("\\input.txt")
check_exists("docs")
check_exists("\\docs")
exit(0)
}
function check_exists(name, fnr,msg,rec) {
while (getline rec <name > 0) {
fnr++
break
}
# "Permission denied" is for MS-Windows
msg = (ERRNO == 0 || ERRNO ~ /Permission denied/ || fnr > 0) ? "exists" : "does not exist"
printf("%s - %s\n",name,msg)
close(name)
}
</lang>
<p>example:</p>
<pre>
ECHO Microsoft Windows example >input.txt
MKDIR docs
MKDIR \docs
GAWK -f CHECK_THAT_FILE_EXISTS.AWK
input.txt - exists
\input.txt - does not exist
docs - exists
\docs - exists
DEL input.txt
RMDIR docs
RMDIR \docs
GAWK -f CHECK_THAT_FILE_EXISTS.AWK
input.txt - does not exist
\input.txt - does not exist
docs - does not exist
\docs - does not exist
</pre>
=={{header|BASIC}}==
{{works with|QBasic}}
477

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.