Check for folder/Drive/File in VB 6


In visual Basic 6.0 you can check the existence of file and folder by utilizing the File System Object. Lets take a look at the sub routine  which check the existence of folder in your system.

Is Dir/Folder Exist

‘Returns a Boolean – True if the file exists

Public Function DirExist(OrigFile As String)
Dim fs
Set fs = CreateObject(“Scripting.FileSystemObject”)
DirExists = fs.folderexists(OrigFile)
End Function

The function return false if the folder check fails.

 Is Drive Exist

Public Function DExists(OrigFile As String)
Dim fs, d
Set fs = CreateObject(“Scripting.FileSystemObject”)
    If fs.driveexists(OrigFile) = True Then
    Set d = fs.getdrive(OrigFile)
    DExists = 1
        If d.isready = True Then
        DExists = 2
        Exit Function
        End If
    Else
    DExists = 0
    End If
End Function

The function return a none zero value if the drive found and active other wise it leave a zero.

And finally the file check and it simple with three line code

File Check

Public Function FExists(OrigFile As String)
Dim fs
Set fs = CreateObject(“Scripting.FileSystemObject”)
FExists = fs.fileexists(OrigFile)
End Function

I thing that is enough to for a code poet to make sure the file exist in the system. Please re share the post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.