<p>使用FSO自动创建多级文件夹的函数</p> <p>开启FSO权限 在 开始-&ldquo;运行&rdquo;中执行regsvr32.exe scrrun.dll即可。如想关闭FSO权限,在上述命令中加/u参数。注册表中的键值位置:HKEY_CLASS_BOOT\F.S.O .FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便。函数:<br /> 以下为引用的内容:<br /> &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 <br /> 调用方法:<br /> 以下为引用的内容:<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>
T:0.008120s,M:246.55 KB
返回顶部 留言