You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ.
The Stata Programming Reference Manual PDF included in your Stata installation contains documentation for the confirm command. It shows no way of using the confirm command to test whether a file is empty (by which I understand you mean the file exists but has no observations of data), It does not seem possible to do what you request.
http://www.stata.com/help.cgi?confirm documents confirm file and confirm new fileas commands to check for existence of named files. These commands have been in Stata for several versions.
However, I share William's puzzlement:
1. To confirm that a file is empty might require reading it in to find nothing.
2. Another method of intercepting an OS command might work but under MS Windows at least I note that dir will happily report 0.0k as the filesize as a rounded figure for a file with content. So, checking for 0.0k is no use.
I need to start by saying that I consider a file to be empty if it exists (e.g. shows in a directory listing) but contains no data. If the question in the original post used "file is empty" to mean "file does not exist" then the task could be accomplished with something like
Code:
capture confirm new file gnxl.txt
if _rc==0 {
display "file gnxl.txt does not exist"
}
But approaching it from my understanding of an "empty file", the original post does not state whether the "empty file" is "a Stata dataset with no observations", on which the techniques Robert refers to would be useful, or instead perhaps "a text file meant to be imported into Stata". The solution to determining if a file that exists is empty depends crucially on the format of the file. That's a hard question, which is why I limited my response to addressing the particular technique suggested in the original post.
Comment