Finding Directory and File

mastana
09-16-2000, 10:07 AM
How can I make a program find out if a particular directory exists on my hard disk and if a particular file exists in a particular directory?
Also would be of great help if someone could tell how to check if a cd-drive exists on the system and it's drive letter.
one more problem, when I use a dirlist and drivelist box, if I click on a:(floppy drive) and there is no floppy in the drive, the program ends with an error, How can I trap this error to prevent this closing.

usetheforce2
09-16-2000, 12:34 PM
for the question bout checking for a valid drive, just error trap it so it does crash your app.If the drive in drive is not valid, a Run-time error '68' device unavailable will be displayed.

Private Sub Command1_Click()
On Error Resume Next
If Len(Text1.Text) > 0 Then
ChDrive Text1.Text
End If
If Err.Number = 0 Then
Text2.Text = CurDir("c:")
Else
Text2.Text = Err.Description
End If
End Sub

This routine uses the ChDrive function to switch the current directory to the value specified in Text1.Text. I then check the Err object to see if an error occurred and display either the error information or the new current directory.

------------------- check directory -------------------

Private Sub Command1_Click()
Dim d As String
Text1.Text = ""
d = Dir(Text2.Text)
Do While Len(d) > 0
Text1.Text = Text1.Text & d & vbCrLf
d = Dir
Loop
End Sub

This routine uses the Dir function to display all of the files in the directory specified by the Text2 text box in the Text1 text box. The first call to Dir specifies the path that I want to search. If a file is found, then I will add it to the Text2 text box and get the next file in the directory by using the Dir function without any parameters.

Best Regards,
Regan DeDiana

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum