  
- UID
- 1
- 威望
- 1240 点
- 金钱
- 24019 金币
- 点卡
- 317 点
|
1#
发表于 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>
复制代码 |
我是一个呼吸着现在的空气而生活在过去的人
这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
我已习惯了孤独,爱上孤独
他让我看清了自我,还原了自我
让我再静静的沉思中得到快乐和满足
再孤独的世界里我一遍又一遍
不厌其烦的改写着自己的过去
延伸到现在与未来
然而那只是泡沫般的美梦
产生的时刻又伴随着破灭的到来
在灰飞烟灭的瞬间我看到的是过程的美丽
而不是结果的悲哀。。。
|
|