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

一个可以自动创建多级目录的函数

本帖由 老林2005-11-18 发布。版面名称:后端开发

  1. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
    '-------------------------------------------------
    '创建多级目录,可以创建不存在的根目录
    '参数:要创建的目录名称,可以是多级
    '返回逻辑值,True成功,False失败
    '创建目录的根目录从当前目录开始
    '---------------------------------------------------
    Function CreateMultiFolder(ByVal CFolder)
    Dim objFSO,PhCreateFolder,CreateFolderArray,CreateFolder
    Dim i,ii,CreateFolderSub,PhCreateFolderSub,BlInfo
    BlInfo = False
    CreateFolder = CFolder
    On Error Resume Next
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    If Err Then
    Err.Clear()
    Exit Function
    End If
    CreateFolder = Replace(CreateFolder,"\","/")
    If Left(CreateFolder,1)="/" Then
    CreateFolder = Right(CreateFolder,Len(CreateFolder)-1)
    End If
    If Right(CreateFolder,1)="/" Then
    CreateFolder = Left(CreateFolder,Len(CreateFolder)-1)
    End If
    CreateFolderArray = Split(CreateFolder,"/")
    For i = 0 to UBound(CreateFolderArray)
    CreateFolderSub = ""
    For ii = 0 to i
    CreateFolderSub = CreateFolderSub & CreateFolderArray(ii) & "/"
    Next
    PhCreateFolderSub = Server.MapPath(CreateFolderSub)
    If Not objFSO.FolderExists(PhCreateFolderSub) Then
    objFSO.CreateFolder(PhCreateFolderSub)
    End If
    Next
    If Err Then
    Err.Clear()
    Else
    BlInfo = True
    End If
    CreateMultiFolder = BlInfo
    End Function

    '使用方法:

    Response.Write CreateMultiFolder("/upload/2005/3/26/") &"<br>"

    Response.Write CraeteMultiFolder("upload\2005\3\26")

    '函数的返回值为True(成功)或False(失败,可以是主机不支持FSO功能)
     
  2. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    啊.哦.好像不错.
     
  3. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
    乡亲们,此贴万万不能顶啊 顶不得....
     
  4. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    :mad:
     
  5. kamsang

    kamsang New Member

    注册:
    2005-10-05
    帖子:
    9,080
    赞:
    58
    来了,就顶一帖吧!
     
  6. 男淫

    男淫 New Member

    注册:
    2005-11-01
    帖子:
    103
    赞:
    0
    不错啊,好,我顶~~