html5中文学习网

您的位置: 首页 > 网络编程 > ASP编程 » 正文

ASP中自动生成多级文件夹的函数(使用FSO)_ASP教程_编程技术

[ ] 已经帮助:人解决问题
FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.

  函数:ZTxHTML5中文学习网 - HTML5先行者学习网

  ' --------------------------------
  ' 自动创建指定的多级文件夹
  ' strPath为绝对路径
  ' 引用请保留版权
  ' by im286_Anjer
  ' 2005-4-3
  Function AutoCreateFolder(strPath) ' As Boolean
On Error Resume NextZTxHTML5中文学习网 - HTML5先行者学习网

Dim astrPath, ulngPath, i, strTmpPath
Dim objFSOZTxHTML5中文学习网 - HTML5先行者学习网

If InStr(strPath, "/") <=0 Or InStr(strPath, ":") <= 0 Then
AutoCreateFolder = False
Exit Function
End If
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
AutoCreateFolder = True
Exit Function
End If
astrPath = Split(strPath, "/")
ulngPath = UBound(astrPath)
strTmpPath = ""
For i = 0 To ulngPath
strTmpPath = strTmpPath & astrPath(i) & "/"
If Not objFSO.FolderExists(strTmpPath) Then
' 创建
objFSO.CreateFolder(strTmpPath)
End If
Next
Set objFSO = Nothing
If Err = 0 Then
AutoCreateFolder = True
Else
AutoCreateFolder = False
End If
  End FunctionZTxHTML5中文学习网 - HTML5先行者学习网

  调用方法:ZTxHTML5中文学习网 - HTML5先行者学习网

  MyPath = "C:/a/b/c/"
  If AutoCreateFolder(MyPath) Then
Response.Write "创建文件夹成功"
  Else
Response.Write "创建文件夹失败"
  End IfZTxHTML5中文学习网 - HTML5先行者学习网

ZTxHTML5中文学习网 - HTML5先行者学习网
ZTxHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助