1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

ASP如何实现生成多级文件夹

本帖由 逆风沉沦2006-04-12 发布。版面名称:后端开发

  1. 逆风沉沦

    逆风沉沦 New Member

    注册:
    2006-01-01
    帖子:
    27
    赞:
    0
  2. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
    代码:
    ' --------------------------------
    ' 自动创建指定的多级文件夹
    ' strPath为绝对路径
    ' 引用请保留版权
    ' by im286_Anjer
    ' 2005-4-3
    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 
     
    
    
    调用方法:
    
    MyPath = "C:\a\b\c\"
    If AutoCreateFolder(MyPath) Then
            Response.Write "创建文件夹成功"
    Else
            Response.Write "创建文件夹失败"
    End If