ex.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 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.
 
' 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