DirList

Description

Populates a ListBox with a list of files. You can specify a path, a mask, and a file type to restrict the set of files displayed. If the window has an associated StaticText control, DirList can display the current drive and directory as well.

Applies to

ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls

Syntax

listboxname.DirList ( filespec, filetype {, statictext } )

Argument

Description

listboxname

The name of the ListBox control you want to populate.

filespec

A string whose value is the file pattern. This is usually a mask (for example, *.INI or *.TXT). If you include a path, it becomes the current drive and directory.

filetype

An unsigned integer representing one or more types of files you want to list in the ListBox. Types are:

  • 0 -- Read/write files

  • 1 -- Read-only files

  • 2 -- Hidden files

  • 4 -- System files

  • 16 -- Subdirectories

  • 32 -- Archive (modified) files

  • 16384 -- Drives

  • 32768 -- Exclude read/write files from the list

To list several types, add the numbers associated with the types. For example, to list read-write files, subdirectories, and drives, use 0+16+16384 or 16400 for filetype.

statictext (optional)

The name of the StaticText in which you want to display the current drive and directory.


Return value

Boolean.

Returns true if the search path is valid so that the ListBox is populated or the list is empty. DirList returns false if the ListBox cannot be populated (for example, filespec is a file, not a directory, or specifies an invalid path). If any argument's value is null, DirList returns null.

Usage

You can call DirList when the window opens to populate the list initially. You should also call DirList in the script for the SelectionChanged event to repopulate the list box based on the new selection. (See the example in DirSelect.)

Alternatives

Although DirList's features allow you to emulate the standard File Open and File Save windows, you can get the full functionality of these standard windows by calling GetFileOpenName and GetFileSaveName instead of DirList.

Examples

This statement populates the ListBox lb_emp with a list of read/write files with the file extension TXT in the search path C:\EMPLOYEE\*.TXT:

lb_emp.DirList("C:\EMPLOYEE\*.TXT", 0)

This statement populates the ListBox lb_emp with a list of read-only files with the file extension DOC in the search path C:\EMPLOYEE\*.DOC and displays the path specification in the StaticText st_path:

lb_emp.DirList("C:\EMPLOYEE\*.DOC", 1, st_path)

These statements in the script for a window Open event initialize a ListBox to all files in the current directory that match *.TXT:

String s_filespec
s_filespec = "*.TXT"
lb_filelist.DirList(s_filespec, 16400, st_filepath)

See also

DirSelect

GetFolder