' create folder directory
'如果它不存在，请创建指定的目录。 如果它们不存在，将创建嵌套的目录。
'FF_MakeDir( ByRef Rep as String ) as Long 
'返回 =0 成功，非0 是出错代码
' //
' //  Create the specified directory if it does not exist.  Will create
' //  nested directories if they do not exist.
' //
Function FF_MakeDir(ByRef Rep As String) As Long
   If Left(Rep, 2) = "\\" Then Exit Function
   
   Dim P1 As Long
   Dim P2 As Long
   Dim ErrCode As Long
   Dim Directory As String
   Dim chm As String
   
   '如果该目录已存在然后简单地退出
   If Dir(Rep) > "" Then Exit Function
   
   Directory = Rtrim(Rep, "\")
   If Len(Directory) Then
      P1 = 1
      Do
         P2 = InStr(P1, Directory, "\")
         If P2 Then
            Chm = Mid(Directory, 1, P2 - 1) : P1 = P2 + 1
         Else
            Chm = Directory
         End If
         If Len(Dir(Chm, 16)) = 0 Then
            If MkDir(Chm) <> 0 Then
               Function = Err : Exit Function
            End If
         End If
      Loop Until P2 = 0
   End If
   
End Function
 
