1. 论坛系统升级为Xenforo,欢迎大家测试!
    Dismiss Notice

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

Discussion in '后端开发' started by 逆风沉沦, Apr 12, 2006.

  1. 逆风沉沦

    逆风沉沦 New Member

    Joined:
    Jan 1, 2006
    Messages:
    27
    Likes Received:
    0
  2. 老林

    老林 New Member

    Joined:
    Sep 6, 2005
    Messages:
    10,580
    Likes Received:
    36
    Code:
    ' --------------------------------
    ' 自动创建指定的多级文件夹
    ' 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