◄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. ' To try this example: ' 1. Choose New Project from the File menu ' 2. Copy the code example below to the code window ' 3. Press F5 to run the example DECLARE FUNCTION GetFileCount& (filespec$) filespec$ = "*.*" count = GetFileCount(filespec$) PRINT count; "files in the current directory match the file specification." ' This function evaluates a file specification and returns the ' number of files that match the specification. Wildcards ("*" and "?") ' are permitted. Drive and directory path specifications may also be included ' in filespec$. CLS ' Clear the screen FUNCTION GetFileCount& (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