在asp操作文件中,遇到了創(chuàng)建多級(jí)文件夾,其實(shí)一級(jí)別的創(chuàng)建文件夾很簡(jiǎn)單,就fso(路徑)即可,但是遇到了多級(jí)文件夾,這就得寫函數(shù)來(lái)創(chuàng)建多級(jí)文件夾
相關(guān):php自動(dòng)創(chuàng)建文件夾
asp自動(dòng)創(chuàng)建多級(jí)文件夾,當(dāng)其中文件夾不存在時(shí),自動(dòng)創(chuàng)建文件夾.
代碼如下:
<%@LANGUAGE = VBScript%>
<%Option Explicit%>
<%'asp版本自動(dòng)創(chuàng)建文件夾
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自動(dòng)創(chuàng)建文件夾函數(shù)開(kāi)始
Function createdir(path)
Dim temp_path,temp_path_array '定義私有路徑
path = Replace(path,"\","/")
' response.write path
If isnull(path) or path = "" Then
createdir = False
Exit Function
End if
If not fso.FolderExists(path) then
'獲取次級(jí)目錄路徑
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)'獲取次級(jí)目錄
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創(chuàng)建多級(jí)文件夾函數(shù)完畢
path = base&"a/b/c"'因?yàn)閜ath獲取站點(diǎn)物理路徑最后包括"/",所以建立文件要以空開(kāi)頭,然后是文件夾名
'response.write path
If (createdir(path)) Then
response.write "已經(jīng)創(chuàng)建"
Else
response.write "創(chuàng)建失敗"
End if
%>
更多信息請(qǐng)查看IT技術(shù)專欄