标题:
用fso建立任意层深的子目录
[打印本页]
作者:
cnangel
时间:
2004-5-14 12:20
标题:
用fso建立任意层深的子目录
作者:狗狗儿
FileSystemObject中有一个CreateFolder方法可以用来建立目录,但只能建立一层的目??
当我们想建
立很多层的目录(如/web/bbs/include/bak)时这个方法就无能为力了.为解决这个问题, 我写
了个BuildPath(strPath)过程,可以完美的解决这个问题.代码如下:
Sub BuildPath(strPath)
On Error Resume Next
Dim nPos,fso,strFolder
nPos = Len(Server.MapPath("/"))
Set fso = CreateObject("Scripting.FileSystemObject")
Do
nPos = InStr(nPos + 1,strPath,"/")
If nPos = 0 Then
strFolder = strPath
Else
strFolder = Left(strPath,nPos - 1)
End If
If fso.FolderExists(strFolder) Then
Response.Write "Err: Folder " & strFolder & " Existed.<br>"
Else
fso.CreateFolder(strFolder)
If Err Then
Response.Write err.description
Else
Response.Write "Folder " & strFolder & " Created.<br>"
End If
End If
Loop Until nPos = 0
End Sub
asp实例:
<%
'BuildPath.asp
'Written By Googler
'www.Googler.uni.cc
Option Explicit
On Error Resume Next
Dim StrPath
strPath = Request("strPath")
If strPath <> "" Then
BuildPath Replace(Server.MapPath(strPath),"\","/")
End If
'---------------------------------------------------------------------------
Sub BuildPath(strPath)
On Error Resume Next
Dim nPos,fso,strFolder
nPos = Len(Server.MapPath("/"))
Set fso = CreateObject("Scripting.FileSystemObject")
Do
nPos = InStr(nPos + 1,strPath,"/")
If nPos = 0 Then
strFolder = strPath
Else
strFolder = Left(strPath,nPos - 1)
End If
If fso.FolderExists(strFolder) Then
Response.Write "Err: Folder " & strFolder & " Existed.<br>"
Else
fso.CreateFolder(strFolder)
If Err Then
Response.Write err.description
Else
Response.Write "Folder " & strFolder & " Created.<br>"
End If
End If
Loop Until nPos = 0
End Sub
%>
<br>
<hr>
<form method=get>
<input type=text name=strPath Lenght=15>
<input type=submit value=Create...>
</form>
复制代码
欢迎光临 星星博客 (http://commerce.huhoo.net/)
Powered by Discuz! 7.0.0