BBS: Inland Empire Archive Date: 11-16-92 (11:16) Number: 381 From: DIK COATES Refer#: NONE To: JIM COYLE Recvd: NO Subj: Determine if file exists Conf: (2) Quik_Bas
In a message from Jim Coyle to David Solly Msg #73, 10-Nov-92 08:23PM Subject: Re: Existing File check 'This file is called "DS.BAS" 'File "SOMEFILE.XXX" does not initially exist in subdirectory... 'using only FILEEXIST% and no function call, gives EXE file size = 48172 bytes 'using only FILEEXIST1% and no function calls, gives EXE file size = 23140 bytes 'therefore, using DIR$ Function yields smaller executable! ' by returning -1 instead of 1 allows BOOLEAN operations... DECLARE FUNCTION FILEEXIST1% (filename$) DECLARE FUNCTION FILEEXIST% (filename$) CLS OPEN "SOMEFILE.XXX" FOR BINARY AS #1 'This is the form for all that follow IF LOF(1) THEN 'test for true, not a numeric value found% = -1 'return -1 and not 1 then boolean NOT works ELSE found% = 0 END IF CLOSE #1 PRINT found%; NOT found% OPEN "DS.BAS" FOR BINARY AS #1 IF LOF(1) THEN found% = -1 ELSE found% = 0 END IF CLOSE #1 PRINT found%; NOT found% OPEN "DS.BAS" FOR BINARY AS #1 IF LOF(1) THEN found% = 1 'return 1 then boolean NOT doesn't work ELSE found% = 0 END IF CLOSE #1 PRINT found%; NOT found% 'NOT for 1 is equal to -2 PRINT '***** In Modular form using LOF Function IF FILEEXIST%("DS.BAS") THEN PRINT "DS.BAS Exists" ELSE PRINT "DS.BAS NOT Exist" END IF IF FILEEXIST%("SOMEFILE.XXX") THEN PRINT "SOMEFILE.XXX Exists" ELSE PRINT "SOMEFILE.XXX NOT Exist" END IF PRINT '***** In Modular form using DIR$ Function IF FILEEXIST%("DS.BAS") THEN PRINT "DS.BAS Exists" ELSE PRINT "DS.BAS NOT Exist" END IF IF FILEEXIST1%("SOMEFILE.XXX") THEN 'function returns true because PRINT "SOMEFILE.XXX Exists" '0 length filename exists ELSE PRINT "SOMEFILE.XXX NOT Exist" END IF KILL "SOMEFILE.XXX" 'destroy the evidence IF FILEEXIST1%("SOMEFILE.XXX") THEN 'function false because PRINT "SOMEFILE.XXX Exists" 'filename NOT exist ELSE PRINT "SOMEFILE.XXX NOT Exist" END IF FUNCTION FILEEXIST% (filename$) temp% = FREEFILE OPEN filename$ FOR BINARY AS temp% 'This is the form for all that follow IF LOF(temp%) THEN 'test for true, not a numeric value FILEEXIST% = -1 'return -1 and not 1 then boolean NOT works ' ELSE 'not needed, included because original code ' FILEEXIST% = 0 'not needed END IF CLOSE #temp% END FUNCTION FUNCTION FILEEXIST1% (filename$) IF LEN(DIR$(filename$)) THEN FILEEXIST1% = -1 END IF END FUNCTION ... Will someone please bind and gag the moderator! -Dik ___ Blue Wave/QWK v2.10 --- Maximus 2.00 * Origin: Durham Systems (ONLINE!) (1:229/110)
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