[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Native file exist check
From: |
Peng Yu |
Subject: |
Native file exist check |
Date: |
Fri, 5 Jun 2020 09:38:07 -0500 |
Hi,
https://stackoverflow.com/questions/29284472/awk-check-file-exists
The following solution is shown above. But getline could potentially
read too much (for example processing a binary file in which a line
can be very long). Is there a more efficient awk native solution for
checking whether a file exist?
function file_exists(file) {
n=(getline _ < file);
if (n > 0) {
print "Found: " file;
return 1;
} else if (n == 0) {
print "Empty: " file;
return 1;
} else {
print "Error: " file;
return 0;
}
}
--
Regards,
Peng
- Native file exist check,
Peng Yu <=
Re: Native file exist check, Andrew J. Schorr, 2020/06/05
Re: Native file exist check, arnold, 2020/06/07