-
I've ready many articles and tutorials, all the same, about how to open and close files. And how to use file boxes to browse for files.
What I wan't to do is be able to check if a directory or file already exists, but without user intervention. An example would be a batch file command like "IF EXIST blah.txt THEN dowhatever"
Is there something like I could use if VB?
-
You can use the Dir Function to check if a file exist.
Code:
Private Sub Command1_Click()
If Dir("C:\test.txt") = "" Then
MsgBox "File dont exist"
Else
MsgBox "File Exist"
End If
End Sub
-
To check if a directory exists, also using the Dir function:
Code:
Private Sub Command1_Click()
If Dir("C:\MyFolder", vbDirectory) <> "" Then
MsgBox "Folder exists"
Else
MsgBox "Folder does not exist"
End If
End Sub