To adapt the tip “File Exists?” (see “101 Hot Tech Tips for VB Developers,” Supplement to the August 1996 issue of VBPJ, page 7) to a directory list box, it is necessary to control the error that occurs when the user selects the root (C:):
Sub Dir1_Change Dim File As String File = Dir1.Path If Right$(File, 1) = "" Then File = File & "himem.sys" Else File = File & "" & "himem.sys" End If ' Chuong Van Huynh's tip If Dir$(File) <> "" Then MsgBox "himem.sys exists !" End IfEnd Sub
Without testing to see if the path already ends with a backslash, as it would when it’s the root directory, an error occurs because of the string “c:\himem.sys.”