GETNAMECOUNT(string-expression)
Returns the number of files in the directory specified by string-expression.
- If the path begins with /, it is treated as a fully qualified path.
- If it does not, it is treated as relative to the current working directory.
Examples
REM Count files in the current directory
PRINT "Current dir has "; GETNAMECOUNT("") ; " files"
REM Relative path example
PRINT "Logs: "; GETNAMECOUNT("logs")
REM Fully qualified path example
PRINT "Programs: "; GETNAMECOUNT("/programs")
REM Guard against empty directories
IF GETNAMECOUNT("/saves") = 0 THEN
PRINT "No saved games found"
ENDIF
Notes
- Counts only files, not subdirectories.
- Returns 0 if the directory exists but has no files.
- Returns 0 if the directory cannot be opened or does not exist.
- The empty string ("") refers to the current directory.
- Works well with GETNAME$ Function$ "GETNAME\$" to iterate over each filename.
See also: GETNAME$ Function$ "GETNAME\$" · OPENIN · OPENOUT · CLOSE