CodeItBetter Programming Another VB Programming Blog

How to Check whether the given Path is Writeable

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'File/Folder Handling - How to Check whether the given Path is Writeable

Option Explicit
 
Public Function IsPathWriteable(ByVal sPath As String) As Boolean
    On Error Resume Next
    Dim TempFileName As String, fn As Long
    TempFileName = MakeTempFileName(sPath)
    fn = FreeFile
    Open TempFileName For Output As #fn
    If Err = 0 Then
        Close #fn
        Kill TempFileName
        IsPathWriteable = True
    Else
        IsPathWriteable = False
    End If
End Function
 
Public Function MakeTempFileName(ByVal sPath 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 sPath = "" Then sPath = App.path
    'To make sure path ends with \.
    If (Right(sPath, 1) <> "\") Then sPath = sPath & "\"
    x = 0
    Do
        x = x + 1
        s = sPath & x & ".tmp"
    Loop Until Dir(s) = ""
    MakeTempFileName = sPath & x & ".tmp"
End Function
 
'How can I call this Function:
Private Sub Form_Load()
    MsgBox IsPathWriteable("C:\Temp\Test\")
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.