Make your own free website on Tripod.com
Check If Path Is Writeable

Author: Peter G. Aitken

Path may point to CD drive, write protected diskette or network path where you do not have write permission. This function check if a path is writeable. The function does not verify whether the path exists. If the path does not exist or is invalid, False is returned, just as if the path exists but is not writable.

Form Code

  Public Function  IsPathWriteable(path As String) As Boolean
' Returns True if path can be written to,
' False otherwise.
On Error Resume Next
Dim TempFileName As String, fn As Integer
TempFileName = MakeTempFileName(path)
fn = FreeFile
Open TempFileName For Output As #fn
' no error - this path is writeable.
If Err = 0 Then
Close #fn
    Kill TempFileName
    IsPathWriteable = True
Else
    IsPathWriteable = False
End If
End Function
Public Function MakeTempFileName(path As String)
' Returns a filename (with path) that is not
' already in use in the indicated path. Name
' has the form path\1.tmp, path\2.tmp, etc.
' If path is blank then App.Path is used.
' Does not verify that path is valid.
Dim x As Integer, s As String
If path = "" Then path = App.path
' Be sure path ends with \.
If (Right(path, 1) <> "\") Then path = path & "\"
x = 0
Do
    x = x + 1
    s = path & x & ".tmp"
Loop Until Dir(s) = ""
MakeTempFileName = path & x & ".tmp"
End Function

Private Sub Form_Load()
    MsgBox IsPathWriteable("d:\")
End Sub

Go Back