bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DIR$ Function Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the DIR$ function within the GetFileCount FUNCTION
'procedure to return the number of files that match the given file
'specification.
 
DECLARE FUNCTION GetFileCount& (filespec$)
 
filespec$ = "*.*"
count = GetFileCount(filespec$)
PRINT count; "files match the file specification."
 
FUNCTION GetFileCount& (filespec$)
'This function evaluates a file specification and returns the
'number of files that match the specification.  Wild card characters
'("*" and "?") are permitted. Drive and directory path specifications
'may also be included in filespec$.
DIM FileCount AS LONG
 
    IF LEN(DIR$(filespec$)) = 0 THEN     'Ensure filespec is valid.
        FileCount& = 0                   'It's not.
    ELSE
        FileCount = 1                    'It is, so count files.
        DO WHILE LEN(DIR$) > 0
            FileCount& = FileCount& + 1
        LOOP
    END IF
    GetFileCount = FileCount&
END FUNCTION