01
'==============================================
02
' 作用:ASP創建多級文件夾,可以創建不存在的根目錄
03
' 參數:要創建的目錄名稱,可以是<span id="__kindeditor_bookmark_start_0__"></span>多級
04
' 返回邏輯值,True成功,<span id="__kindeditor_bookmark_end_1__"></span>False失敗
05
' 創建目錄的根目錄從當前目錄開始
06
' 自動創建指定的多級文件夾
07
' strPath為絕對路徑
08
'==============================================
09
Function
AutoCreateFolder(strPath)
'As Boolean
10
''On Error Resume Next
11
Dim
astrPath, ulngPath, i, strTmpPath
12
Dim
objFSO
13
If
InStr(strPath,
"\") <=0 or InStr(strPath, "
:") <= 0
Then
14
AutoCreateFolder =
False
15
Exit
Function
16
End
If
17
Set
objFSO = Server.CreateObject(
"Scripting.FileSystemObject"
)
18
If
objFSO.FolderExists(strPath)
Then
19
AutoCreateFolder =
True
20
Exit
Function
21
End
If
22
astrPath = Split(strPath, "\")
23
ulngPath = UBound(astrPath)
24
strTmpPath =
""
25
For
i = 0
To
ulngPath
26
strTmpPath = strTmpPath & astrPath(i) & "\"
27
If
Not
objFSO.FolderExists(strTmpPath)
Then
28
'創建
29
objFSO.CreateFolder(strTmpPath)
30
End
If
31
Next
32
Set
objFSO =
Nothing
33
If
Err = 0
Then
34
AutoCreateFolder =
True
35
Else
36
AutoCreateFolder =
False
37
End
If
38
End
Function