Monday, October 14, 2013

Is it there? Files and Folders

Which "it"?  The file or folder, referenced in code.  

Here are a couple of handy, no UI to fix errors so they run more quickly, utilities to make certain that character string points to a file or folder.  The differentiating line is highlighted

Function IsAvailableFolder(Optional FolderWithPath) As Boolean
    On Error GoTo IsAvailableFolder_Error
    IsAvailableFolder = (GetAttr(FolderWithPath) And vbDirectory) = vbDirectory
    GoTo IsAvailableFolder_Exit
    IsAvailableFolder = False
    On Error GoTo 0
End Function

Function IsAvailableFile(Optional FileWithPath) As Boolean
    On Error GoTo IsAvailableFile_Error
    IsAvailableFile = Not (GetAttr(FileWithPath) And vbDirectory) = vbDirectory
    GoTo IsAvailableFile_Exit
    IsAvailableFile = False
    On Error GoTo 0
End Function

No comments:

Post a Comment