当前位置: 移动技术网 > IT编程>开发语言>.net > ASP技巧:使用FSO自动创建多级文件夹的函数

ASP技巧:使用FSO自动创建多级文件夹的函数

2019年01月18日  | 移动技术网IT编程  | 我要评论

情侣个性签名,骷髅闯世传说,小清新电脑桌面

开启fso权限 在 开始-“运行”中执行regsvr32.exe scrrun.dll即可。如想关闭fso权限,在上述命令中加/u参数。注册表中的键值位置:hkey_class_bootf.s.o .fso中有个方法是createfolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.函数:

’ --------------------------------
’ 自动创建指定的多级文件夹
’ 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:ac"
if autocreatefolder(mypath) then
        response.write "创建文件夹成功"
else
        response.write "创建文件夹失败"
end if

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网