在ASP中自动创建多级文件夹的函数(使用FSO)

当当全新正版图书,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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值