SoFunction
Updated on 2025-04-13

Automatically generate n-layer directories using functions

First check whether the directory already exists. If it exists, no processing will be done, and if it does not exist, it will be created.
I hope it will be useful for you to develop quickly.


<%
'***********************************************************************************************************
'Author: Zhao Min flash90@
'Page name:
'Page function: Generate folders for n-level directories
'Usage method: Call CheckFolder() function, for example: CheckFolder(path)
'Passage: The relative path of the file to be uploaded, for example: path = "./upload/bbb/ccc/ddd"
'Disfigure: You must include the upload folder in the parameter path
'***********************************************************************************************************
Sub CheckFolder(path)
SplitPath(path)
End Sub
Sub SplitPath(path)
dim Road 'Physical Path
Road = ("./upload")
dim CurRoad 'Current path
Road = Split(Road,"\",-1,1)
CurRoad = Road(UBound(Road))
dim folder,FSO
Set FSO = ("")
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 = (".\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 = ("")
if Not((mypath+"/"+folderName)) then
set f = (mypath+"/"+folderName)
end if
End Sub
Set fso = nothing
%>