• 使用FSO自动创建多级文件夹

    您当前的位置:首页 > 课程详解>使用FSO自动创建多级文件夹

    使用FSO自动创建多级文件夹

    时间:2014-11-13 17:24:36  来源:北大青鸟accp  作者:郑州北大青鸟

    文章摘要
    使用FSO自动创建多级文件夹一直是很多朋友所不太熟悉的,对于这个问题北大青鸟的老师在本文给出了详细的解答,希望在看过此文后能够对于使用FSO自动创建多级文件夹有所认识。

    使用FSO自动创建多级文件夹一直是很多朋友所不太熟悉的,对于这个问题北大青鸟的老师在本文给出了详细的解答,希望在看过此文后能够对于使用FSO自动创建多级文件夹有所认识。
    当我们用fso来生成静态页面的时候,通常都会希望生成的位置能整洁,明了。比如按年月日来划分,那么就会需要得到一个形如:“2009/6/”这样或者更多级的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便。
    函数:

    ’ --------------------------------
    ’ 自动创建指定的多级文件夹
    ’ strPath为绝对路径
    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:abc"
    If AutoCreateFolder(MyPath) Then
    Response.Write "创建文件夹成功"
    Else
    Response.Write "创建文件夹失败"
    End If
    上文介绍的使用FSO自动创建多级文件夹就到这里,不知道大家是否了解了呢? 北大青鸟老师希望同学们在学习中遇到这个问题能够通过自己的思考独立解决。

    郑州北大青鸟财大校区
    分享到: