FILE HANDLING

 BBS: Inland Empire Archive
Date: 02-11-93 (11:32)             Number: 343
From: DOUGLAS LUSHER               Refer#: NONE
  To: OWEN GIBBINS                  Recvd: NO  
Subj: FILE HANDLING                  Conf: (2) Quik_Bas
 OG>Are there any functions in QuickBASIC similar to the EXIST and NOT
 OG>EXIST functions in batch files?

 Owen: there is no built in function in QB that will do what you want,
 but I believe there is in PDS. Below is a function that you can add to
 QB to acomplish the task. Be sure to load QB with the /L switch,
 and add '$INCLUDE: 'QB.BI' to the beginning of your program. Use it
 like this:
 File$ = "MYFILE.BAS"
 IF FileExists%(File$) THEN
   PRINT "The file "; File$; " actually exists!"
 ELSE
   PRINT "The file "; File$; " isn't there."
 END IF

 Here's the function:

 FUNCTION FileExists% (FileName$)
 'returns True (-1) if the specified file exists, returns False (0)
 'otherwise
 DIM XRegister as RegTypeX

  'save the current DTA
  XRegister.AX = &H2F00
  CALL InterruptX(&H21, XRegister, XRegister)
  OldDTASeg% = XRegister.ES
  OldDTAOff% = XRegister.BX

  'set up a new DTA
  DTA$ = SPACE$(43)
  XRegister.AX = &H1A00
  XRegister.DS = VARSEG(DTA$)
  XRegister.DX = SADD(DTA$)
  CALL InterruptX(&H21, XRegister, XRegister)

 ' *** get first matching file
 TempFileName$ = FileName$ + CHR$(0)
 XRegister.AX = &H4E00
 XRegister.CX = &H6                'find normal, hidden & system  files
 XRegister.DS = VARSEG(TempFileName$)
 XRegister.DX = SADD(TempFileName$)
 CALL InterruptX(&H21, XRegister, XRegister)
 FileExists% = ((XRegister.Flags AND 1) = 0)   'if the carry flag is
                                               'clear, the file exists
 'restore the original
 DTA XRegister.AX = &H1A00
 XRegister.DS = OldDTASeg%
 XRegister.DX = OldDTAOff%
 CALL InterruptX(&H21, XRegister, XRegister)

END FUNCTION

---
  SLMR 2.1a  All hope abandon, ye who enter messages here.

--- TMail v1.30.4
 * Origin: TC-AMS MLTBBS 2.2 - Minnetonka, MN (612)-938-4799 (1:282/7)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET