Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Capture confirm

    Hello. How could I use -capture confirm- to confirm if a file is empty or not?

  • #2
    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.

    Comment


    • #3
      http://www.stata.com/help.cgi?confirm documents confirm file and confirm new file as 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.

      Last edited by Nick Cox; 24 Sep 2015, 07:36.

      Comment


      • #4
        See this thread for various techniques of getting the file size.

        Comment


        • #5
          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

          Working...
          X