在ASP中自动创建多级文件夹的函数
作者:佚名 文章来源:网络转载 更新时间
:2007-11-26 1:00:27
FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.
函数:
CODE:
' --------------------------------
' 自动创建指定的多级文件夹
' strPath为绝对路径
' 引用请保留版权
' by im286_Anjer
' 2005-4-3
Function AutoCreateFolder(strPath) ' As Boolean
On Error Resume Next
Dim astrPath, ulngPath, i, strTmpPath
Dim objFSO
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 Function
调用方法:
CODE:
MyPath = "C:\a\b\c\"
If AutoCreateFolder(MyPath) Then
Response.Write "创建文件夹成功"
Else
Response.Write "创建文件夹失败"
End If
【相关文章:】
关于在asp中使用Include的一些问题
[转帖]Asp中常用的时间函数
在ASP中用递归算法遍历硬盘上的目录和文件
在ASP应用中如何限制同一表单被多次提交
在ASP中使用“Request”时应注意的问题
在asp中通过getrows实现数据库记录分页的一段代码
树型结构在ASP中的简单解决
ASP中使用Session变量的优缺点
在asp文件中访问flash详细信息
在ASP与ASP.NET之间共享对话状态(2)
【发表评论】【打印此文】【关闭窗口】【点击数: 】
函数:
' 自动创建指定的多级文件夹
' strPath为绝对路径
' 引用请保留版权
' by im286_Anjer
' 2005-4-3
Function AutoCreateFolder(strPath) ' As Boolean
On Error Resume Next
Dim astrPath, ulngPath, i, strTmpPath
Dim objFSO
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 Function
调用方法:
If AutoCreateFolder(MyPath) Then
Response.Write "创建文件夹成功"
Else
Response.Write "创建文件夹失败"
End If
【相关文章:】
关于在asp中使用Include的一些问题
[转帖]Asp中常用的时间函数
在ASP中用递归算法遍历硬盘上的目录和文件
在ASP应用中如何限制同一表单被多次提交
在ASP中使用“Request”时应注意的问题
在asp中通过getrows实现数据库记录分页的一段代码
树型结构在ASP中的简单解决
ASP中使用Session变量的优缺点
在asp文件中访问flash详细信息
在ASP与ASP.NET之间共享对话状态(2)
【发表评论】【打印此文】【关闭窗口】【点击数: 】
★好玩的休闲小游戏★
网友评论:
数据载入中,请稍后……
