Laurent
Here are three functions I use for directory creating etc.
you are welcome to them as is.
Roy Low
www.low.net.au
Sub DirCreate(ByVal NewPath$, errorcode%)
' Sub to create a directory NewPath$ if it does not exist already
'NewPath$ = "d:\a\b\c"
errorcode% = 0
If direxist%(NewPath$) Then Exit Sub
'Make sure it is a full path without a terminating \
NewPath$ = Trim$(NewPath$)
If InStr(NewPath$, " ") <> 0 Then
errorcode% = 3
Exit Sub
End If
If Mid$(NewPath$, 2, 2) <> ":\" Then
errorcode% = 1
Exit Sub
End If
NewPath$ = convpathStr$(NewPath$, "")
n% = CountStr%(NewPath$, "\", last%)
On Error GoTo BadDirStr
For i% = 2 To n%
s$ = getfldstr$(NewPath$, "\", i%, X%)
d$ = Left$(NewPath$, X% - 2)
If Not direxist%(d$) Then
MkDir d$
End If
Next i%
MkDir NewPath$
Exit Sub
BadDirStr:
errocode% = 2
End Sub
Function direxist%(dirn$)
' This function returns true if a directory dirn$ exists
' otherwise false
'first remove any trailing "\"
dirn2$ = convpathStr$(dirn$, "")
If Len(dirn2$) = 0 Then Exit Function
On Local Error GoTo Dirxerr
nof% = FreeFile
Open dirn2$ & "\dum~~.t~~" For Output As nof%
direxist% = True
Close nof%
Kill dirn2$ & "\dum~~.t~~"
Exit Function
Dirxerr:
'Reset Removed and replaced with close nof% 29/11/96
Close nof%
Select Case Err
Case 76 'path not found
Resume dirnoex
Case 64, 68 'Invalid dir name, Device Unavailable
Resume dirnoex 'treat as not found
Case 70 'permission denied (write protected FD when dir exists)
s$ = Space$(20) & "WARNING" & lf$
s$ = s$ & "The floppy disk " & Left$(dirn2$, 2) & " is Write-protected."
s$ = s$ & lf$ & "Correct the situation and press Enter"
MsgBox s$, 0, "Checking Existence of Directory " & dirn2$
Resume
Case 71 'disk not ready
s$ = "The floppy disk " & Left$(dirn2$, 2) & " is not ready."
s$ = s$ & lf$ & "Correct the situation and press Enter"
s$ = s$ & lf$ & "or press ESC to Quit."
If MsgBox(s$, 1, "Checking Existence of Directory " & dirn2$) = 1 Then
Resume
Else
Resume dirnoex
End If
Case Else
s$ = "Unexpected Error Condition."
s$ = s$ & lf$ & "Error No. " & Str$(Err)
s$ = s$ & lf$ & Error$
MsgBox s$, 0, "Checking Existence of Directory " & dirn2$
Resume dirnoex
End Select
Resume dirnoex
dirnoex:
direxist% = False
End Function
Function dirvalid%(dirn$)
' This function returns true if
' a directory name dirn$ can validly be created or exists
' otherwise false
'first remove any trailing "\"
dirn2$ = convpathStr$(dirn$, "\")
If Len(dirn2$) = 0 Then Exit Function
' Guard against problems with unmounted or write protected Floppies
Fd$ = UCase$(Left$(dirn2$, 2))
If Fd$ = "A:" Or Fd$ = "B:" Then
X% = direxist%(Fd$ & "\")
Reset
End If
If direxist%(dirn$) Then
dirvalid% = True
Exit Function
End If
' Dirn$ does not exist - try to make it
On Local Error GoTo Dirverr
Call DirCreate(dirn2$, errorcode%)
If errorcode% = 0 Then
' remove it
RmDir dirn2$
dirvalid% = True
Exit Function
Else
dirvalid% = False
Exit Function
End If
'MkDir dirn2$
' remove it
'RmDir dirn2$
'dirvalid% = True
'Exit Function
Dirverr:
MsgBox "Unexpected error in DIRVALID Function." & lf$ & Error$ & Str$(Err)
Resume dirnbad
dirnbad:
dirvalid% = False
End Function
Quote:
>Hello,
>How can you find out if a specific path exists or not?