Working with the FileSystem Control

The FileSystem control is an ActiveX control that provides access to the files and directories on a Windows CE-based device. Through the FileSystem control, you can manage directories and delete files. You also can determine when a file was created, and you can set the file attributes, such as whether a file is read-only, hidden, or archive.

The FileSystem control does not use properties or events. Instead, it supplies methods that perform all file system functions. For example, the MkDir and RmDir methods are used to create and delete directories. Although you can use the RmDir method to delete a directory, you must use the Kill method to delete a file. In addition, because the FileSystem control creates only directories, you must use the File control to create files.

You can determine what files and directories already exist by using the Dir method. To provide information about existing directories and files, the control uses the FileDateTime and GetAttr methods. In addition, there are two other methods you can use with files. The FileLen method returns the length of a file and the SetAttr method sets file attributes. You also can copy, move, or rename existing files with the MoveFile and CopyFile methods.

To use the Dir method, you must specify the path names and attributes of the items you want to return. The first call to the Dir method must contain a path name. To get additional file names and directories that match the path name, call Dir again with no parameters. When no more file names match, Dir returns a zero-length string (""). Once a zero-length string is returned, you must specify a path name again. Dir supports the use of multiple-character (*) and single-character (?) wildcards.

The following code example shows how to use the Dir method to obtain a list of subdirectories.

Public Sub ShowAllDirs(DPath)
    'DPath must include *.* to show all directories
    Dim FAttr As FileAttrEnum
    Dim DName As String
    Dim DList As String
    FAttr = fsAttrDirectory
    'Get first item that matches DPath and
    'is also a directory
    DName = FileSystem1.Dir(DPath, FAttr)
    'Get the rest of the matches
    Do While DName <> ""
        DList = DList & DName & vbCrLf
        DName = FileSystem1.Dir
    Loop
    'Show the matching directories
    MsgBox DList, , "Directories matching " & DPath
End Sub