asp中創(chuàng)建多級目錄的兩段代碼
更新時間:2007年03月20日 00:00:00 投稿:mdxy-dxy
這篇文章主要介紹了asp中創(chuàng)建多級目錄的兩段代碼,需要的朋友可以參考下
實(shí)現(xiàn)代碼一、比較專業(yè)看起來
'==============================
'創(chuàng)建多級目錄,可以創(chuàng)建不存在的根目錄
'參數(shù):要創(chuàng)建的目錄名稱,可以是多級
'創(chuàng)建目錄的根目錄從當(dāng)前目錄開始
'''調(diào)用舉例
''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
上面的是循環(huán)
實(shí)現(xiàn)方法二、
'自動創(chuàng)建多極目錄
'code by jb51 reterry
function createit(path)
dim fsofo,cinfo,thepath,thepatharray
dim i,ii,binfo
binfo=false
thepath=path
set fsofo=createobject("scripting.filesystemobject")
if err then
err.clear
exit function
end if
thepath=replace(thepath,"\","/")
if left(thepath,1)="/" then
thepath=right(thepath,len(thepath)-1)
end if
if right(thepath,1)="/" then
thepath=left(thepath,len(thepath)-1)
end if
thepatharray=split(thepath,"/")
for i=0 to ubound(thepatharray)
createfoldersub1=createfoldersub1&thepatharray(i)&"/"
createfoldersub=server.mappath(createfoldersub1)
if not fsofo.folderexists(createfoldersub) then
fsofo.createfolder(createfoldersub)
end if
next
if err then
err.clear
else
binfo=true
end if
createit=binfo
end function
下面的是通過正則實(shí)現(xiàn)
'==============================
''創(chuàng)建文件目錄(多層)
''使用正則
'==============================
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
以上就是asp中創(chuàng)建多級目錄的兩段代碼的詳細(xì)內(nèi)容,更多關(guān)于asp創(chuàng)建多級目錄的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:
相關(guān)文章
可以應(yīng)用到馬克斯電影站生成Rss Feed的代碼
前段時間為了給本人的電影站增加Rss訂閱功能,動手寫了個動態(tài)生成Rss Feed的ASP代碼,沒法上傳附件,就直接貼代碼吧,反正也不長,用馬克斯做電影站的朋友直接拿去用吧,其它類型的站點(diǎn)修改一下也能用。生成的Rss Feed采用UTF-8編碼,經(jīng)過feedvalidator.org校驗(yàn),兼容Rss 2.0和Atom。2008-03-03
asp IsValidEmail 驗(yàn)證郵箱地址函數(shù)(email)
驗(yàn)證郵箱很多在js客戶端驗(yàn)證了,但是那樣很容易被人破了,我們在服務(wù)器上用asp進(jìn)行驗(yàn)證的話就應(yīng)該沒有問題了。2010-05-05
利用ASP從遠(yuǎn)程服務(wù)器上接收XML數(shù)據(jù)的方法
利用ASP從遠(yuǎn)程服務(wù)器上接收XML數(shù)據(jù)的方法...2007-01-01
從一個網(wǎng)站扒下的asp生成靜態(tài)頁面的代碼 腳本之家特供版
雖然腳本之家以前發(fā)布過相關(guān)的代碼,但一些特別的網(wǎng)站不是很完美,最近幫客戶修改系統(tǒng)發(fā)現(xiàn)了這段代碼,發(fā)現(xiàn)還不錯,特提取出來,方便大家使用。2011-07-07
將首頁轉(zhuǎn)成靜態(tài)html頁的asp文件
將首頁轉(zhuǎn)成靜態(tài)html頁的asp文件...2007-03-03

