<p>在ASP中自动创建多级文件夹的函数</p> <p>FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.<br /> 函数:<br /> <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, &quot;\&quot;) &lt;=0 Or InStr(strPath, &quot;:&quot;) &lt;= 0 Then<br /> AutoCreateFolder = False<br /> Exit Function<br /> End If<br /> Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> If objFSO.FolderExists(strPath) Then<br /> AutoCreateFolder = True<br /> Exit Function<br /> End If<br /> astrPath = Split(strPath, &quot;\&quot;)<br /> ulngPath = UBound(astrPath)<br /> strTmpPath = &quot;&quot;<br /> For i = 0 To ulngPath<br /> strTmpPath = strTmpPath &amp; astrPath(i) &amp; &quot;\&quot;<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 /> </p> <p>调用方法:<br /> MyPath = &quot;C:\a\b\c\&quot;<br /> If AutoCreateFolder(MyPath) Then<br /> Response.Write &quot;创建文件夹成功&quot;<br /> Else<br /> Response.Write &quot;创建文件夹失败&quot;<br /> End If</p>
返回顶部 留言