ASP技巧:使用FSO自动创建多级文件夹的函数

2014 年 8 月 10 日4780

  ’--------------------------------
’自动创建指定的多级文件夹
’strPath为绝对路径
FunctionAutoCreateFolder(strPath)’AsBoolean
OnErrorResumeNext
DimastrPath,ulngPath,i,strTmpPath
DimobjFSO
IfInStr(strPath,"\")<=0OrInStr(strPath,":")<=0Then
AutoCreateFolder=False
ExitFunction
EndIf
SetobjFSO=Server.CreateObject("Scripting.FileSystemObject")
IfobjFSO.FolderExists(strPath)Then
AutoCreateFolder=True
ExitFunction
EndIf
astrPath=Split(strPath,"\")
ulngPath=UBound(astrPath)
strTmpPath=""
Fori=0ToulngPath
strTmpPath=strTmpPath&astrPath(i)&"\"
IfNotobjFSO.FolderExists(strTmpPath)Then
’创建
objFSO.CreateFolder(strTmpPath)
EndIf
Next
SetobjFSO=Nothing
IfErr=0Then
AutoCreateFolder=True
Else
AutoCreateFolder=False
EndIf
EndFunction

  MyPath="C:\a\b\c\"
IfAutoCreateFolder(MyPath)Then
Response.Write"创建文件夹成功"
Else
Response.Write"创建文件夹失败"
EndIf

  

标签:

网络编程 ASP

0 0