安大互联
财经热点 > Asp编程 > ASP中自动生成多级文件夹的函数(使用FSO)
ASP中自动生成多级文件夹的函数(使用FSO)
浏览次数:【14】  发布日期:2009-8-13 12:09:22    文章分类:Asp编程   
专题:】 【
 

  函数:

  ' --------------------------------
  ' 自动建立指定的多级文件夹
  ' 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

手机扫码浏览该文章
 ● 相关资讯专题
  • 网络建设业务咨询

   TEl:13626712526