<%
Const wexRoot = "/x/binaries/"
wexRootPath = RealizePath(wexRoot)
Function FixPath(path, slash)
    If Right(path, 1) <> slash Then
           FixPath = path & slash
       Else
        FixPath = path
       End If
End Function

Function RealizePath(path)
    Dim fpath
    fpath = replace(path,"/","\")
    If left(fpath,1) = "\" Then ‘Virtual path
        on error resume next
        RealizePath = server.MapPath(fpath)
        If err.Number<>0 Then RealizePath = fpath ‘Possibly network path
    Else ‘Physical Path
        RealizePath = fpath
    End If
    RealizePath = FixPath(RealizePath, "\")
End Function

Function CreateFolder(itemName)

    itemPath = wexRootPath & itemName

    Set FSO = server.CreateObject ("Scripting.FileSystemObject")

    on error resume next
    Response.Buffer = true

    If FSO.FolderExists(itemPath) = false and FSO.FileExists(itemPath) = false Then
        FSO.CreateFolder(itemPath)
        If err.Number <> 0 Then
            wexMessage = "Unable to create the folder """ & itemName & """, an error occured…"
        Else
            wexMessage = "Created the folder """ & itemName & """…"
        End If
    Else
        wexMessage = "Unable to create the folder """ & itemName & """, there exists a file or a folder with the same name…"
    End If

    Set FSO = nothing
    response.write wexMessage
    response.write "<br>" & itemPath
End Function
%>

Create folder

<%
CreateFolder "My New Folder"
%>

Leave a Reply