'Listing 29.2 Staranny sposb kodowania


' Tworzenie katalogu zgodnie z zawartoci zmiennej DestPath$
' pierwszy znak musi by symbolem napdu dyskowego, za ktrym 
' opcjonalnie wystpuj ":\" i  cieka
'--------------------------------------------------------------------------

Function CreatePath (ByVal DestPath) As Integer
  Dim backpos, forepos As Integer
  Dim temp As String
  '
  ' dodaj backslash na kocu cieki, jeeli jeszcze go tam nie ma
  ' --------------------------------------------------------------
  '
  If Right$(DestPath, 1) <> "\" Then
    DestPath = DestPath + "\"
  End If
  '
  ' Przejd do gwnego katalogu dysku
  '------------------------------------
  '
  On Error Resume Next
  ChDrive DestPath
  If Err <> 0 Then GoTo errorOut
  ChDir "\"
  backpos = 3
  forepos = inStr(4, var1, "\")
  Do While forepos <> 0
    temp = Mid$(DestPath, backpos + 1, forepos - backpos - 1)
    Err = 0
    MkDir temp 
    If Err <> 0 And Err <> 75 Then GoTo errorOut
    Err = 0
    ChDir temp
    If Err <> 0 Then Goto errorOut
    backpos = forepos
    forepos = InStr(backpos + 1, DestPath, "\")
  Loop
  CreatePath = True
  Exit Function
  '
errorOut:
  If Err = 71 Then
    MsgBox "Please insert Disk in Drive"
    Resume
  End If
  CreatePath = False
End Function
