<p>ASP中自动生成多级文件夹的函数</p>
<p>FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.</p>
<p> 函数:<br />
' --------------------------------<br />
' 自动创建指定的多级文件夹<br />
' strPath为绝对路径<br />
' 引用请保留版权<br />
' by im286_Anjer<br />
' 2005-4-3<br />
Function AutoCreateFolder(strPath) ' As Boolean<br />
On Error Resume Next<br />
Dim astrPath, ulngPath, i, strTmpPath<br />
Dim objFSO<br />
If InStr(strPath, "") <=0 Or InStr(strPath, ":") <= 0 Then<br />
AutoCreateFolder = False<br />
Exit Function<br />
End If<br />
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")<br />
If objFSO.FolderExists(strPath) Then<br />
AutoCreateFolder = True<br />
Exit Function<br />
End If<br />
astrPath = Split(strPath, "")<br />
ulngPath = UBound(astrPath)<br />
strTmpPath = ""<br />
For i = 0 To ulngPath<br />
strTmpPath = strTmpPath & astrPath(i) & ""<br />
If Not objFSO.FolderExists(strTmpPath) Then<br />
' 创建<br />
objFSO.CreateFolder(strTmpPath)<br />
End If<br />
Next<br />
Set objFSO = Nothing<br />
If Err = 0 Then<br />
AutoCreateFolder = True<br />
Else<br />
AutoCreateFolder = False<br />
End If<br />
End Function<br />
调用方法:<br />
MyPath = "C:abc"<br />
If AutoCreateFolder(MyPath) Then<br />
Response.Write "创建文件夹成功"<br />
Else<br />
Response.Write "创建文件夹失败"<br />
End If</p>