Error 53 ("File Not Found") Using FILES "filespec" Statement (58214)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1
  • Microsoft GW-BASIC 3.2
  • Microsoft GW-BASIC 3.22
  • Microsoft GW-BASIC 3.23

This article was previously published under Q58214

SUMMARY

The FILES "filespec" statement prints the names of the files residing on the specified disk. However, the manual doesn't mention that if the "filespec" parameter does not describe any current filenames, an error 53 ("File Not Found") is returned. Unless this error is trapped, program execution is halted.

MORE INFORMATION

When a FILES statement is used to list the files in a specific directory and the pattern that FILES is searching for does not exist, an error 53 ("File Not Found") is returned.

If the error is not trapped by the program, the error message "File Not Found" is displayed in the interpreter environment. In executable programs, the message displayed is "File Not Found In Module [Filename] at SEG:OFF," where SEG:OFF represents the segment and the offset from that segment of code where the error happened.

To avoid halting the program, the program needs only to trap the error 53 that is returned to the program. The program examples below demonstrate this, assuming that a file named ABC.XYZ does not exist on the root directory of drive C.

Example for Compiled Basics -- BASPROG.BAS

   ON ERROR GOTO ErrorHandle
   FILES "c:\abc.xyz"
   END
   ErrorHandle:
      IF ERR = 53 THEN PRINT "Error 53 was trapped. File not found."
   RESUME NEXT
				
You can compile and link BASPROG.BAS as follows in QuickBasic 4.00, 4.00b, or 4.50, Basic compiler 6.00 or 6.00b, or Basic PDS 7.00:
   BC /x Basprog;
   LINK Basprog;
				
Use QB /x Basprog in QuickBasic Versions 2.00, 2.01, 3.00.

Use BASCOM /x Basprog in QuickBasic Versions 1.00, 1.01, 1.02.

Example for GW-Basic Interpreter

   10 ON ERROR GOTO 999
   20 FILES "c:\abc.xyz"
   30 END
   999  IF ERR = 53 THEN PRINT "Error 53 was trapped. File not found."
   1000 RESUME NEXT
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB58214