-
1. How can I check if a directory exists and a file exists?
2. If I use a drivelist box to set the drive, along with the dirlist box, if I click on a:(floppy drive), without putting in a floppy it generates an error(because the chdir is related to chdrive)and the program terminates. How can I trap this error to tell the user to put in a floppy in the drive?
-
#1) Use the Dir() function.
Code:
If Dir$("MyFile.txt") <> "" Then
'File Exists
Else
'File does not exist
End If
#2) It's a simple matter of Error Handling.
Code:
Private Sub Drive1_Change()
On Error GoTo ERRH
Dir1 = Drive1
ERRH:
If Err = 68 Then MsgBox "Drive not ready. Insert disk", vbCritical + vbOKOnly, "Error"
End Sub