先檢查是否已經存在該目錄了,如果存在,則不做任何處理,如果不存在則創建。
希望對各位快速開發有用。
CheckFolder.asp
<%
'***********************************************************************************************************
'作 者: 趙敏
[email protected]
'頁面名稱: CreateFolder.asp
'頁面功能: 生成n層目錄的文件夾
'使用方法: 調用CheckFolder()函數,例如: CheckFolder(path)
'傳入參數: 即將上傳的文件的相對路徑,例如: path = "./upload/bbb/ccc/ddd"
'缺 點: 必須在參數path裡面帶上upload文件夾
'***********************************************************************************************************
Sub CheckFolder(path)
SplitPath(path)
End Sub
Sub SplitPath(path)
dim Road '物理路徑
Road = Server.Mappath("./upload")
dim CurRoad '當前路徑
Road = Split(Road,"\",-1,1)
CurRoad = Road(UBound(Road))
dim folder,FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
folder = Split(path,"\",-1,1)
for i = 0 to UBound(folder) step 1
if folder(i) = CurRoad then
j = i
exit for
end if
Next
i = j + 1
if i <= UBound(folder) then
dim myroad
myroad = Server.MapPath(".\upload")
for i = j + 1 to UBound(folder) step 1
CreateFolder myroad,folder(i)
myroad = myroad &"/"& folder(i)
Next
end if
End Sub
Sub CreateFolder(mypath,folderName)
Dim fso,f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if Not(fso.FolderExists(mypath+"/"+folderName)) then
set f = fso.CreateFolder(mypath+"/"+folderName)
end if
End Sub
Set fso = nothing
%>