Automatically create multilevel folders using the FSO

Source: Internet
Author: User
Tags exit end
When we use the FSO to generate static pages, we usually want the generated location to be neat and clear. For example, by year and month, then you will need to get a shape such as "2009/6/" or more levels of folders, so I wrote a function to create a multi-level folder automatically, in the generation of static pages, such as the use of very convenient.

When we use the FSO to generate static pages, we usually want the generated location to be neat and clear. For example, by year and month, then you will need to get a shape such as "2009/6/" or more levels of folders, so I wrote a function to create a multi-level folder automatically, in the generation of static pages, such as the use of very convenient.

Function:

’ --------------------------------
' Automatically create a specified multilevel folder
' strpath is an absolute path
Function Autocreatefolder (strpath) ' as Boolean '
On Error Resume Next
Dim Astrpath, Ulngpath, I, strTmpPath
Dim objFSO
If InStr (strpath, "\") <=0 Or InStr (strpath, ":") <= 0 Then
Autocreatefolder = False
Exit Function
End If
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
If objfso.folderexists (strpath) Then
Autocreatefolder = True
Exit Function
End If
Astrpath = Split (strpath, "\")
Ulngpath = UBound (Astrpath)
strTmpPath = ""
For i = 0 to Ulngpath
strTmpPath = strTmpPath & Astrpath (i) & "\"
If not objfso.folderexists (strTmpPath) Then
' Create
Objfso.createfolder (strTmpPath)
End If
Next
Set objFSO = Nothing
If ERR = 0 Then
Autocreatefolder = True
Else
Autocreatefolder = False
End If
End Function

Call Method:

MyPath = "C:\a\b\c\"
If Autocreatefolder (MyPath) Then
Response.Write "Create folder succeeded"
Else
Response.Write "Create folder Failed"
End If



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.