Jump to content

Check that file exists: Difference between revisions

(Nimrod -> Nim)
Line 127:
# syntax: GAWK -f CHECK_THAT_FILE_EXISTS.AWK
BEGIN {
check_existsexists("input.txt")
check_existsexists("\\input.txt")
check_existsexists("docs")
check_existsexists("\\docs")
exit(0)
}
 
function check_exists(name, fnr,msg,rec) {
#
while (getline rec <name > 0) {
# Check if file or directory exists, even 0-length file.
fnr++
# Return 0 if not exist, 1 if exist
break
#
}
function exists(file ,line, msg)
# "Permission denied" is for MS-Windows
{
msg = (ERRNO == 0 || ERRNO ~ /Permission denied/ || fnr > 0) ? "exists" : "does not exist"
while if ( (getline recline <name > 0file) {== -1 )
printf("%s - %s\n",name,msg)
close(name) {
# "Permission denied" is for MS-Windows
msg = (ERRNO == 0 || msg = (ERRNO ~ /Permission denied/ || fnrERRNO >~ 0/a directory/) ? "exists1" : "does not exist0"
close(file)
return msg
fnr++ }
else {
close(file)
return 1
break }
}
</lang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.