File Related Commands
VB supports several drive and directory commands
that prepare the file list controls. The following
table shows these commands:
Command |
Description |
chDrive strDrive |
Changes the
current drive |
chDir strDir |
Changes the
current directory or folder |
Kill strFile |
Deletes files
from a disk |
MkDir strDir |
Creates a new
directory or folder |
RmDir |
Removes an existing
directory or folder |
VB also supports the following functions:
Dir(): It checks whether or not files exist.
CurDir(): It returns the name of the current directory
Example
Private Sub dirFolders_Change()
filFiles.Path = dirFolders.Path
End Sub
Private Sub drvDisk_Change()
dirFolders.Path = drvDisk.Drive
End Sub
VB makes it possible to create a chain reaction among
the File controls, automatically updating any power
control in the hierarchy if an upper-level control
is changed. The first chain reaction is the DriveListBox
control providing drive information to the DirListBox
control. To chain the DirListBox to the DriveListBox
control, add the following statement to drvDisk_Change()
sub procedure.
dirFolders.Path = drvDisk.Drive
When you click a new folder in the DirListBox control,
or when the directory changes because the drive changed,
the change needs to be relayed to the file list box.
To chain the FileListBox to the DirListBox, the following
statement is added:
filFiles.Path = dirFolders.Path
|
|
Today's lesson explained about
the File controls. Although the Common dialog
box control works best for offering File Open
and File save dialog boxes, you can place the
file controls on forms when you need specific
information on a drive, directory, or file.
|
|