If checking for a zero-byte file was as simple as opening the file, we could:
[tt]
ff = FREEFILE
OPEN "TEST.TXT" FOR BINARY AS #ff
PRINT "TEST.TXT IS" ; LOF(ff) ; " BYTES LONG."
CLOSE #ff
[/tt]
One of the problems with opening a file to get it's size is that the act of opening creates a zero-byte file, if one didn't already exist. Unlike Visual Basic, QB doesn't provide a handy way to get the length of a file... but it's a fairly simple matter to get that information (and
more) with the DOS interrupts:
[tt]
DEFINT A-Z
TYPE RegTypeX
AX AS INTEGER
BX AS INTEGER
CX AS INTEGER
DX AS INTEGER
bp AS INTEGER
Si AS INTEGER
DI AS INTEGER
Flags AS INTEGER
DS AS INTEGER
ES AS INTEGER
END TYPE
DIM inRegs AS RegTypeX, Outregs AS RegTypeX
'Let's look for a file in the current directory called "TEST.TXT"
SearchFile$ = "TEST.TXT" + CHR$(0)
'Get the address of the Disk Transfer Area
inRegs.AX = &H2F00
CALL INTERRUPTX(&H21, inRegs, Outregs)
SegDTA = Outregs.ES
OffDTA = Outregs.BX
'Find first matching file. (Find a match for "TEST.TXT"
inRegs.DS = VARSEG(SearchFile$)
inRegs.DX = SADD(SearchFile$)
inRegs.CX = &HFF
inRegs.AX = &H4E00
CALL INTERRUPTX(&H21, inRegs, Outregs)
IF Outregs.Flags AND 1 THEN
PRINT SearchFile$; " was not found."
'If the file doesn't exist, quit.
SYSTEM
END IF
'Peek into the DTA to get the file size
DEF SEG = SegDTA
S$ = ""
FOR Re = OffDTA + 26 TO OffDTA + 29
S$ = S$ + CHR$(PEEK(Re))
NEXT
MyFileSize& = CVL(S$)
IF MyFileSize& = 0 THEN
PRINT "File is zero bytes."
ELSE
PRINT "File size: "; MyFileSize&; " bytes"
END IF
DEF SEG
[/tt]
Real men don't use Interrupt 21h.