在ASP中自动创建多级文件夹的函数(使用FSO)
2008-12-04 10:50
501 查看
当当全新正版图书,9周年店庆,特价销售,全场免运费!
FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.
函数:
' --------------------------------
' 自动创建指定的多级文件夹
' 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
调用方法:
MyPath = "C:/a/b/c/"
If AutoCreateFolder(MyPath) Then
Response.Write "创建文件夹成功"
Else
Response.Write "创建文件夹失败"
End If
FSO中有个方法是CreateFolder,但是这个方法只能在其上一级文件夹存在的情况下创建新的文件夹,所以我就写了一个自动创建多级文件夹的函数,在生成静态页面等方面使用非常方便.
函数:
' --------------------------------
' 自动创建指定的多级文件夹
' 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
调用方法:
MyPath = "C:/a/b/c/"
If AutoCreateFolder(MyPath) Then
Response.Write "创建文件夹成功"
Else
Response.Write "创建文件夹失败"
End If
相关文章推荐
- 在ASP中自动创建多级文件夹的函数(使用FSO)
- asp.net 创建文件夹时出错:未找到路径“D:\”的一部分。(asp.net 使用 FSO)
- asp结合fso实现文件或文件夹创建删除等操作的函数
- Asp按月份自动创建文件夹函数
- 自动检测创建多级目录, fso与stream生成文件函数
- 使用ASP创建文件夹的一个函数
- asp结合fso实现文件或文件夹创建删除等操作的函数
- Windows下使用创建多层文件夹 SHCreateDirectoryEx 函数需要注意的问题
- 使用C#创建webservice及三种调用方式 (ASP.NETweb编程常用到的27个函数集)
- asp fso读取文件夹,如何按照(1:按创建时间 2:按访问时间 3:按修改时间 4:按名称)排序(2008-09-18,11:19:18)
- 【ASP.NET】怎样使用类创建公共函数,在不同ASP.NET页面间反复调用
- 使用ASP在IIS创建WEB站点的函数
- asp fso读取文件夹,如何按照(1:按创建时间 2:按访问时间 3:按修改时间 4:按名称)排序(2008-09-18,11:19:18)
- 一个可以自动创建多级目录的函数
- 一个可以自动创建多级目录的函数
- ASP创建多级无限文件夹
- ASP如何检测某文件夹是否存在,不存在则自动创建
- 使用ASP和ASP.NET来创建文件夹和文件。
- asp fso读取文件夹,如何按照(1:按创建时间 2:按访问时间 3:按修改时间 4:按名称)排序(2008-09-18,11:19:18)