当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp中创建多级目录的两段代码

ASP
ASP中实现限制IP的函数详解
Asp下实现限制IP访问的程序代码
asp下DateDiff 函数参数说明
Highlight patterns within strings
Insert Date and Time into Access
asp下调试程序的debug类
RESPONSE.WRITE和<%=%的区别
用asp实现网页邮箱访问的方法
编写一个含二级目录的源码(Asp+JavaScript)
asp下删除Access数词库中的空记录的sql语句
asp下制做行背景颜色交替变换的表格
asp下将数据库中的信息存储至XML文件中
asp下如何在Access数据库中立即得到所插入记录的自动编号?
asp下如何在ADO服务器端利用好缓存技术?
asp调用Word打印的代码
巧用FileSystem组件实现WEB应用中的本地特定打印的方法
用javascript解决外部数据抓取中的乱码问题
Asp中随机产生用户密码的代码
反SPAM新思路—换Z-BLOG的验证码!
在Z-BLOG可用的新版ASP的GIF验证码[V70404]

ASP 中的 asp中创建多级目录的两段代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 35 ::
收藏到网摘: n/a

复制代码 代码如下:

'==============================
'创建多级目录,可以创建不存在的根目录
'参数:要创建的目录名称,可以是多级
'创建目录的根目录从当前目录开始
'''调用举例
''Call CreateMultiFolder("/upload/jumbot/myphoto/")
'==============================
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
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

上面的是循环
下面的是正则
复制代码 代码如下:

'==============================
''创建文件目录(多层)
''使用正则
'==============================
Function Create_N_Folder(save, ByVal Path)
Dim Fso
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
If Not Fso.FolderExists(Path) Then
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "^(.*)\\([^\\]*)$"
regEx.Global = False
regEx.IgnoreCase = True
save = save & regEx.Replace(Path, "$2") & "|"
Path = regEx.Replace(Path, "$1")
If Create_N_Folder(save, Path) Then Create_N_Folder = True
Set regEx = Nothing
Else
If save = "|" Then
Create_N_Folder = True
Else
Dim Temp
Temp = Mid(save, 2, Len(save) - 2)
If InStrRev(Temp, "|") = 0 Then
save = "|"
Path = Path & "\" & Temp
Else
Dim Folder
Folder = Mid(Temp, InStrRev(Temp, "|") + 1)
save = "|" & Mid(Temp, 1, InStrRev(Temp, "|") - 1) & "|"
Path = Path & "\" & Folder
End If
Fso.CreateFolder Path
If Create_N_Folder(save, Path) Then Create_N_Folder = True
End If
End If
Set Fso = Nothing
End Function