BBS: Inland Empire Archive Date: 04-19-92 (11:37) Number: 86 From: MIKE AVERY Refer#: NONE To: DAVID POSKIE Recvd: NO Subj: Re: Using Shell Conf: (2) Quik_Bas
DP> How about using: DP> SHELL "if exist FILENAME.EXT echo y>temp.$" DP> That should work in all versions, past, present, and future. Yeah, DP> I just agreed that an ASM FileExist is the way to go. But old DP> ideas die hard. ;) Under DOS, the redirection will ALWAYS be executed. Sometimes the file will be a zero length file, sometimes it will have a "Y" in it, but it will always be created. This may not be what you want. In an issue of BASIC-PRO I have around here, but can't find, our own Dave Cleary suggested the following.... DEFINT A-Z DECLARE FUNCTION DIR$ (FileSpec$) ' $INCLUDE: 'QB.BI' 'used by call interrupt ' Some constants that Dir$ users CONST DOS = &H21 CONST SetDTA = &H1A00 CONST FindFirst = &H4E00, FindNext = &H4F00 IF LEN(DIR$("c:\usr\qb45\source\dir$.bas")) THEN PRINT "File Found!!" ELSE PRINT "File Not Found!!" END IF PRINT DIR$("c:\usr\qb45\source\dir$.bas") STOP FUNCTION DIR$ (FileSpec$) STATIC DIM DTA AS STRING * 44, Regs AS RegType Null$ = CHR$(0) '-- Set up a local Disk Transfer Area (DTA) Regs.AX = SetDTA 'Set DTA function Regs.DX = VARPTR(DTA) 'DX points to locat DTA INTERRUPT DOS, Regs, Regs 'Call the interrupt '-- See if this is FindFirst or FindNext request IF LEN(FileSpec$) THEN 'find first FileSpecZ$ = FileSpec$ + Null$ 'make ASCIIZ for DOS Regs.AX = FindFirst 'Find First file Regs.CX = 0 'match normal files Regs.DX = SADD(FileSpecZ$) 'DX points to spec ELSE 'it's a null string Regs.AX = FindNext 'so find next name END IF INTERRUPT DOS, Regs, Regs 'Call the interrupt '-- return file name or null IF Regs.flags AND 1 THEN 'No files found DIR$ = "" 'so return null string ELSE Null = INSTR(31, DTA, Null$) 'get the file name DIR$ = MID$(DTA, 31, Null - 30) 'strip the trailing chr$(0) END IF END FUNCTION It looks pretty nice, and gives you access to file information without shelling. As to the "Never shell" argument, I'll stand aside and watch the fireworks, as it is an area of interest where I have not formed opinion at this time.... Thanks for the code Dave, Mike --- via Silver Xpress V3.00 * Origin: Silver Xpress Mail System (1:382/10@fidonet)
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