FSO創(chuàng)建多級文件夾發(fā)布者:本站 時間:2020-05-06 16:05:21
FSO中有個方法是CreateFolder,但是這個方法只能在其上一級文件夾存在的情況下創(chuàng)建新的文件夾,所以我就寫了一個自動創(chuàng)建多級文件夾的函數(shù),在生成靜態(tài)頁面等方面使用非常方便.
函數(shù):
' --------------------------------
' 自動創(chuàng)建指定的多級文件夾
' strPath為絕對路徑
' 引用請保留版權(quán)
' by im286_Anjer
' 2005-4-3
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
' 創(chuàng)建
objFSO.CreateFolder(strTmpPath)
End If
Next
Set objFSO = Nothing
If Err = 0 Then
AutoCreateFolder = True
Else
AutoCreateFolder = False
End If
End Function
調(diào)用方法:
MyPath = "C:abc"
If AutoCreateFolder(MyPath) Then
Response.Write "創(chuàng)建文件夾成功"
Else
Response.Write "創(chuàng)建文件夾失敗"
End If
選擇我們,優(yōu)質(zhì)服務,不容錯過
1. 優(yōu)秀的網(wǎng)絡資源,強大的網(wǎng)站優(yōu)化技術(shù),穩(wěn)定的網(wǎng)站和速度保證
2. 15年上海網(wǎng)站建設經(jīng)驗,優(yōu)秀的技術(shù)和設計水平,更放心
3. 全程省心服務,不必擔心自己不懂網(wǎng)絡,更省心。
------------------------------------------------------------
24小時聯(lián)系電話:021-58370032