Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!usc!ucselx!crash!pro-sol.cts.com!mdavis From: mdavis@pro-sol.cts.com (Morgan Davis) Newsgroups: comp.sys.apple2 Subject: Re: Applesoft problem: finding the end of a text file Message-ID: <7127@crash.cts.com> Date: 22 Jan 91 05:56:14 GMT Sender: root@crash.cts.com Lines: 43 In-Reply-To: message from dunadan@blake.u.washington.edu Here's a trick for finding the end of file of a text file from Applesoft under BASIC.SYSTEM. It is pretty fast, and requires no extensive error handling. 10 FILE$ = "your file name goes here" 20 D$ = CHR$(4) : EOF = 48840 30 PRINT D$ "APPEND" FILE$ 40 PRINT D$ "CLOSE" FILE$ 50 SIZE = PEEK (EOF) + PEEK (EOF + 1) * 256 + PEEK (EOF + 2) * 65536 50 PRINT FILE$ " contains " SIZE " bytes" The magic here is that when you do an APPEND, BASIC.SYSTEM opens the file and does a GET_EOF call in order to move the file pointer to the end of the file. After closing the file, the end of file value is still intact at $BEC8 (48840). You can make this a general purpose file-size-getter by inserting and changing these lines: 25 PRINT D$ "VERIFY" FILE$ 30 PRINT D$ "APPEND" FILE$ ",T" PEEK(48824) After a VERIFY (which is a GET_FILE_INFO MLI call), the file's information such as type, aux type, etc., is left intact in memory. The only problem with this code is that it might balk on locked files, as the APPEND assumes a WRITE. I haven't test it against a locked file, but you can. BTW, in MD-BASIC this kind of tricky coding is amazingly simple and clean. As an example for those of you with MD-BASIC, here is the equivalent code: File$ = "your file name goes here" fVerify File$ fAppend File$ ",T" PEEK(_FIFILID) Size = peek24(_SEOF) PRINT File$ " contains " Size " bytes" --Morgan Davis UUCP: crash!pro-sol!mdavis AOL, BIX: mdavis ARPA: crash!pro-sol!mdavis@nosc.mil GEnie: m.davis42 INET: mdavis@pro-sol.cts.com ProLine: mdavis@pro-sol