در ويژوال بيسيک چگونه تعيين کنيم مسير (Path) قابل نوشتن است يا خير؟
دوشنبه 17 فروردین 1388 5:28 PM
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