Еще одна подпрограмма для подсчета каталогов / имен файлов в QB45:
DECLARE SUB CheckSpec (Var$, Var1!, Var2!)
REM subroutine to count directories\filenames in QB pd 2019 ejo
REM load QB /L QB.QLB
REM links qb.lib into qb.qlb
REM link /q qb.lib,qb.qlb,Nul,bqlb45.lib;
TYPE DTAtype
Drive AS STRING * 1
SearchTemplate AS STRING * 11
SearchAttr AS STRING * 1
EntryCount AS STRING * 2
ClusterNumber AS STRING * 2
Reserved AS STRING * 4
Filebits AS STRING * 1
FileTime AS STRING * 2
FileDate AS STRING * 2
FileSize AS STRING * 4
ASCIIZfilename AS STRING * 13
END TYPE
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
DECLARE SUB InterruptX (intnum AS INTEGER, inreg AS RegTypeX, outreg AS RegTypeX)
DO
COLOR 15, 0
PRINT "Enter filespec(*.*)";
INPUT Filespec$
IF Filespec$ = "" THEN Filespec$ = "*.*"
COLOR 14, 0
PRINT "Searching: "; Filespec$
CALL CheckSpec(Filespec$, Var1, Var2)
COLOR 15, 0
IF Var1 THEN PRINT "Directories:"; Var1
IF Var2 THEN PRINT "Filenames:"; Var2
IF Var1 = 0 AND Var2 = 0 THEN PRINT "No files foound."
COLOR 14, 0
PRINT "Again(y/n)?";
LOCATE , , 1
DO
x$ = INKEY$
IF LCASE$(x$) = "n" THEN PRINT : COLOR 7, 0: END
IF LCASE$(x$) = "y" THEN PRINT : COLOR 7, 0: EXIT DO
LOOP
LOOP
END
' var1=dirs, var2=files
SUB CheckSpec (Var$, Var1, Var2)
DIM InregsX AS RegTypeX
DIM OutregsX AS RegTypeX
DIM DTAfile AS DTAtype
DIM ASCIIZ AS STRING * 260
DIM Current.DTA.SEG AS INTEGER
DIM Current.DTA.OFF AS INTEGER
ASCIIZ = UCASE$(Var$) + CHR$(0)
Var1 = 0: Var2 = 0
' store current dta
InregsX.AX = &H2F00
CALL InterruptX(&H21, InregsX, OutregsX)
Current.DTA.SEG = OutregsX.ES
Current.DTA.OFF = OutregsX.BX
' store function dta
InregsX.AX = &H1A00
InregsX.DS = VARSEG(DTAfile)
InregsX.DX = VARPTR(DTAfile)
CALL InterruptX(&H21, InregsX, OutregsX)
' findfirst
InregsX.AX = &H4E00
InregsX.CX = &H37
InregsX.DS = VARSEG(ASCIIZ)
InregsX.DX = VARPTR(ASCIIZ)
CALL InterruptX(&H21, InregsX, OutregsX)
' check carry flag error
DO
IF (OutregsX.flags AND &H1) = &H0 THEN
' store filename attribute bits
Filebits% = ASC(DTAfile.Filebits)
' check directory bit
IF (Filebits% AND &H10) = &H10 THEN
Var1 = Var1 + 1
ELSE
Var2 = Var2 + 1
END IF
' find next filename
InregsX.AX = &H4F00
CALL InterruptX(&H21, InregsX, OutregsX)
ELSE
EXIT DO
END IF
LOOP
' restore current dta
InregsX.AX = &H1A00
InregsX.DS = Current.DTA.SEG
InregsX.DX = Current.DTA.OFF
CALL InterruptX(&H21, InregsX, OutregsX)
END SUB