Check that file exists: Difference between revisions
Content added Content deleted
No edit summary |
Catskill549 (talk | contribs) |
||
Line 97: | Line 97: | ||
}</lang> |
}</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}}== |
=={{header|BASIC}}== |
||
{{works with|QBasic}} |
{{works with|QBasic}} |