Using FILES$ or FILES to Display Filename or Disk Directory (32724)






This article was previously published under Q32724

SUMMARY

The FILES$ function and the FILES statement cannot display files based on the letters in the filenames. Wild cards in filenames, such as the "*" or "?" symbols supported in MS-DOS file commands, are not supported in BASIC for the Macintosh. (For example, the MS-DOS command DIR *.DOC displays all files with .DOC in the name; however, BASIC for the Macintosh does not have a similar feature.)

Although the FILES statement can send a disk directory to the screen, there is no easy feature to send a disk directory to a file or array, except through calls to Toolbox routines. (For more information, query on the word "HFSDispatch".)

Note that the CHDIR command affects the file folder (subdirectory) displayed by the FILES statement, but CHDIR does NOT affect the file folder displayed by the FILES$(1) function. FILES$(1) always displays the files in the folder where the source file is located (if run in the interpreter), or the files in the folder where the compiled program apl file is located (if run from a compiled program). The FILES$(1) window lets you manually look through other folders with the mouse.

This information applies to Microsoft QuickBASIC Version 1.00, Microsoft BASIC Compiler Version 1.00, and Microsoft BASIC Interpreter Version 3.00 for the Apple Macintosh.

MORE INFORMATION

The FILES$(n) function (where n can be 0 or 1) and the FILES statement offer different capabilities.

The FILES$(n) function can be used to display all files of a certain type and to return one selected filename in a string variable. For example, x$=FILES$(1,"TEXT") displays a dialog box listing all files of type TEXT. The following program displays a scroll box containing all files of type APPL (applications) and TEXT:
   x$=FILES$(1,"TEXTAPPL")
   PRINT X$   ' Prints the name of the one selected file.
				


The FILES statement displays on the screen the filenames in the "current" folder and drive. On a 400K disk, all files will display regardless of their folders; however, on 800K or hard disks, only the files in the current folder will display. (The current folder is defined as the folder in which the BASIC interpreter or compiled program is located.)

BASIC's current folder can be changed with the CHDIR command. For example, the following program changes the current folder on the disk called "HD 20" to a folder called "System," and the FILES statement displays the files in that folder:
CHDIR "HD 20:System:"
FILES
				
A colon (:) is required after both the disk name and folder name, as shown above.

The CHDIR statement affects the folder displayed by the FILES statement, but NOT the folder displayed by default by the FILES$(1) function. The FILES$(1) function displays a scrolling dialog box which lets you manually change folders (subdirectories) with the mouse.

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB32724