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

2018-09-06 11:20

阅读:489

  复制代码 代码如下:
==============================
创建多级目录,可以创建不存在的根目录
参数:要创建的目录名称,可以是多级
创建目录的根目录从当前目录开始
调用举例
CallCreateMultiFolder(/upload/jumbot/myphoto/)
==============================

FunctionCreateMultiFolder(ByValCFolder)
DimobjFSO,PhCreateFolder,CreateFolderArray,CreateFolder
Dimi,ii,CreateFolderSub,PhCreateFolderSub,BlInfo
BlInfo=False
CreateFolder=CFolder
OnErrorResumeNext
SetobjFSO=Server.CreateObject(Scripting.FileSystemObject)
IfErrThen
Err.Clear()
ExitFunction
EndIf
IfRight(CreateFolder,1)=/Then
CreateFolder=Left(CreateFolder,Len(CreateFolder)-1)
EndIf
CreateFolderArray=Split(CreateFolder,/)
Fori=0ToUBound(CreateFolderArray)
CreateFolderSub=
Forii=0Toi
CreateFolderSub=CreateFolderSub&CreateFolderArray(ii)&/
Next
PhCreateFolderSub=Server.MapPath(CreateFolderSub)
IfNotobjFSO.FolderExists(PhCreateFolderSub)Then
objFSO.CreateFolder(PhCreateFolderSub)
EndIf
Next
IfErrThen
Err.Clear()
Else
BlInfo=True
EndIf
CreateMultiFolder=BlInfo
EndFunction

上面的是循环
下面的是正则
复制代码 代码如下:
==============================
创建文件目录(多层)
使用正则
==============================

FunctionCreate_N_Folder(save,ByValPath)
DimFso
SetFso=Server.CreateObject(Scripting.FileSystemObject)
IfNotFso.FolderExists(Path)Then
DimregEx
SetregEx=NewRegExp
regEx.Pattern=^(.*)\\([^\\]*)$
regEx.Global=False
regEx.IgnoreCase=True
save=save&regEx.Replace(Path,$2)&
Path=regEx.Replace(Path,$1)
IfCreate_N_Folder(save,Path)ThenCreate_N_Folder=True
SetregEx=Nothing
Else
Ifsave=Then
Create_N_Folder=True
Else
DimTemp
Temp=Mid(save,2,Len(save)-2)
IfInStrRev(Temp,)=0Then
save=
Path=Path&\&Temp
Else
DimFolder
Folder=Mid(Temp,InStrRev(Temp,)+1)
save=&Mid(Temp,1,InStrRev(Temp,)-1)&
Path=Path&\&Folder
EndIf
Fso.CreateFolderPath
IfCreate_N_Folder(save,Path)ThenCreate_N_Folder=True
EndIf
EndIf
SetFso=Nothing
EndFunction


评论


亲,登录后才可以留言!