一聚教程网:一个值得你收藏的教程网站

热门教程

自动创建多级目录,有则跳过 无则创建,

时间:2022-07-02 23:04:46 编辑:袖梨 来源:一聚教程网

 Function AutoCreateFolder(strPath) ' As Boolean
  On Error Resume Next

  Dim astrPath, ulngPath, i, strTmpPath
  Dim objFSO

  If InStr(strPath, "") <=0 or InStr(strPath, ":") <= 0 Then
   AutoCreateFolder = False
   Exit Function
  End If
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists(strPath) Then
   AutoCreateFolder = True
   Exit Function
  End If
  astrPath = Split(strPath, "")
  ulngPath = UBound(astrPath)
  strTmpPath = ""
  For i = 0 To ulngPath
   strTmpPath = strTmpPath & astrPath(i) & ""
   If Not objFSO.FolderExists(strTmpPath) Then
    ' 创建
    objFSO.CreateFolder(strTmpPath)
   End If
  Next
  Set objFSO = Nothing
  If Err = 0 Then
   AutoCreateFolder = True
  Else
   AutoCreateFolder = False
  End If
 End Function

热门栏目