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