<p>使用FSO自动创建多级文件夹一直是很多朋友所不太熟悉的,对于这个问题达内的老师在本文给出了详细的解答,希望在看过此文后能够对于使用FSO自动创建多级文件夹有所认识。<br /> 当我们用fso来生成静态页面的时候,通常都会希望生成的位置能整洁,明了。比如按年月日来划分,那么就会需要得到一个形如:&ldquo;2009/6/&rdquo;这样或者更多级的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便。<br /> 函数:</p> <p>&rsquo; --------------------------------<br /> &rsquo; 自动创建指定的多级文件夹<br /> &rsquo; strPath为绝对路径<br /> Function AutoCreateFolder(strPath) &rsquo; 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 /> &rsquo; 创建<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</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<br /> 上文介绍的使用FSO自动创建多级文件夹就到这里,不知道大家是否了解了呢?达内老师希望同学们在学习中遇到这个问题能够通过自己的思考独立解决。</p>
T:0.006346s,M:246.56 KB
返回顶部 留言