网站制作学习网ASP→正文:asp自动创建文件夹
字体:

asp自动创建文件夹

ASP 2010/3/22 17:51:36  点击:不统计


在asp操作文件中,遇到了创建多级文件夹,其实一级别的创建文件夹很简单,就fso(路径)即可,但是遇到了多级文件夹,这就得写函数来创建多级文件夹
相关:php自动创建文件夹

asp自动创建多级文件夹,当其中文件夹不存在时,自动创建文件夹.代码如下:
<%@LANGUAGE = VBScript%>  
<%Option Explicit%>
<%'asp版本自动创建文件夹forasp.cn
Dim fso,fso_flag,base,path,i
set fso = CreateObject("Scripting.FileSystemObject")
If isobject(fso) Then
fso_flag = True
Else
fso_flag = false
End If'
If not fso_flag Then response.write"不支持fso.",response.End()
base = request.ServerVariables("APPL_PHYSICAL_PATH")'获取本地基本物理路径
'asp自动创建文件夹函数开始
Function createdir(path)
Dim temp_path,temp_path_array '定义私有路径forasp.cn
path = Replace(path,"\","/")
' response.write path
If isnull(path) or path = "" Then
createdir = False
Exit Function
End if
If not fso.FolderExists(path) then
'获取次级目录路径
temp_path_array = Split(path,"/")
For i = 0 To UBound(temp_path_array)-1
temp_path =  temp_path&temp_path_array(i)&"/"
Next'
temp_path = Left(temp_path,Len(temp_path)-1)'获取次级目录
if createdir(temp_path) Then
fso.CreateFolder (path)
createdir = true
End If
else'www.forasp.cn
createdir = true
Exit Function
End if
End Function
'asp创建多级文件夹函数完毕
forasp.cn
path = base&"a/b/c"'因为path获取站点物理路径最后包括"/",所以建立文件要以空开头,然后是文件夹名
'response.write path
If (createdir(path)) Then
response.write "已经创建"
Else
response.write "创建失败"
End if
%>
网站制作学习网原创,转载请注明http://www.forasp.cn


转www.载for网站制作学习asp必.cn究

·上一篇:asp购物车 >>    ·下一篇:asp获取当前物理路径 >>
推荐文章
最新文章