Path exists or not? 
Author Message
 Path exists or not?

Hello,

How can you find out if a specific path exists or not?
(I don't need to find out if a file belongs to that path, only if the path
exists)
If it doens't exist I want to create it.

The Dir function causes an error 76 (Path doesn't exist!). I can catch that
error (On Error Goto ...), but isn't there a more elegant method?

Laurent Meurisse
GOODYEAR Fabric Plant Luxembourg



Mon, 04 Dec 2000 03:00:00 GMT  
 Path exists or not?

Laurent

What's inelegant about catching errors? That's what they are there for.

Regards
{*filter*}

Quote:

>Hello,

>How can you find out if a specific path exists or not?
>(I don't need to find out if a file belongs to that path, only if the
path
>exists)
>If it doens't exist I want to create it.

>The Dir function causes an error 76 (Path doesn't exist!). I can catch
that
>error (On Error Goto ...), but isn't there a more elegant method?

>Laurent Meurisse
>GOODYEAR Fabric Plant Luxembourg



Mon, 04 Dec 2000 03:00:00 GMT  
 Path exists or not?

Try this code

If Dir(Path, vbDirectory + vbHidden + vbReadOnly) <> "" Then
    If GetAttr(Path) And vbDirectory Then
        MsgBox ("Folder exists")
        If GetAttr(Path) And vbHidden Then MsgBox (" but hidden")
        If GetAttr(Path) And vbReadOnly Then MsgBox (" but read only - can
not be deleted")
    Else
        MsgBox "exists as file"
    End If
Else
    MsgBox "Does not exist"
End If

Good luck
Bo Lundgren



Quote:
> Hello,

> How can you find out if a specific path exists or not?
> (I don't need to find out if a file belongs to that path, only if the
path
> exists)
> If it doens't exist I want to create it.

> The Dir function causes an error 76 (Path doesn't exist!). I can catch
that
> error (On Error Goto ...), but isn't there a more elegant method?

> Laurent Meurisse
> GOODYEAR Fabric Plant Luxembourg



Tue, 05 Dec 2000 03:00:00 GMT  
 Path exists or not?

You might like to try the following function.
Note that a path with trailing "\" (eg. "c:\windows\") returns false by
design.

Regards
Barry Evans
'====================================
Public Function DirExists(PathName As String) As Boolean

    On Error GoTo DirExists_Exit

    Dim Result As Boolean   ' Default function result = False
    Dim strDir As String

    strDir = Dir(PathName, vbDirectory)
    If strDir <> vbNullString Then  ' could use "Len(strDir) > 0"
        If Left(strDir, 1) <> "." Then
            Result = (GetAttr(PathName) And vbDirectory) = vbDirectory
        End If
    End If

DirExists_Exit:
    DirExists = Result

End Function
'====================================

Quote:

>Hello,

>How can you find out if a specific path exists or not?
>(I don't need to find out if a file belongs to that path, only if the path
>exists)
>If it doens't exist I want to create it.

>The Dir function causes an error 76 (Path doesn't exist!). I can catch that
>error (On Error Goto ...), but isn't there a more elegant method?

>Laurent Meurisse
>GOODYEAR Fabric Plant Luxembourg



Sat, 09 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Path exists or not?

2. files exists or not - says that it doesn't exist

3. File existing or not existing?

4. Long Path Names give Runtime error 76 - Path not found

5. fRefreshLinks Doesn't work if path doesn't exist

6. Existing Database Path

7. Checking if folder/path exists: Outlook Form

8. Check if path exists

9. How to check if a path exists

10. File exists in Dos Path?

11. Finding if File and Path Exists?

12. Reading Target path from *existing* shortcut files.

 

 
Powered by phpBB® Forum Software