请教关于Fso生成文件自动生成目录的问题

bbsddn 2008-10-22 10:43:00
原有代码如下:

Function HtmlSave(Url,FileSavePath)
Dim Fso,Str
HtmlSave=false
Str=GetHttpPage(Url)
If Str="" Then Exit Function
If FsObject1=0 Then
Set Fso = Server.Createobject(FsObject)
Set Fso = Fso.CreateTextFile(Server.mappath(FileSavePath))
Fso.Write Str
Fso.Close:Set Fso=NoThing
Else
Set Fso = Server.CreateObject("ADODB.Stream")
Fso.Type = 2
Fso.Open
Fso.Charset = "GB2312"
Fso.Position = Fso.Size
Fso.WriteText Str
Fso.SaveToFile FileSavePath,2
Fso.close:Set Fso=Nothing
End If
HtmlSave=True
End Function

页面代码如下:
HtmlSave "http://"&Application(CacheName&"_WebSetting")(6)&"/news.asp?id="&id,"../html/news/ceshi11/"&id&".htm" '生成html开始
response.redirect "ok_news.asp"

问题:加入news目录里无ceshi11目录,如何让文件生成时同时自动生成目录呢?
...全文
142 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bbsddn 2008-10-22
  • 打赏
  • 举报
回复
非常感谢,已经搞定,采用的VBScript code的代码
已经测试完成。
Atai-Lu 2008-10-22
  • 打赏
  • 举报
回复

Sub createDir(dirName)
dirName=Server.MapPath(dirName)
set fso=Server.CreateObject("scripting.filesystemobject")
if not fso.folderexists(dirName) then'不存在的时候
set dir=fso.createfolder(dirName)'创建总目录
end if
'fso.close
set fso=nothing
End Sub
call createDir("../html/")
call createDir("../html/news/")
call createDir("../html/news/ceshi11/")
HtmlSave "http://"&Application(CacheName&"_WebSetting")(6)&"/news.asp?id="&id,"../html/news/ceshi11/"&id&".htm" '生成html开始

或者

Public Function CheckPath(physicalPath)
Dim fso,arrPhysicalPath,i,strPath
Set fso = CreateObject("Scripting.FileSystemObject")
arrPhysicalPath = Split(physicalPath,"\")
strPath = ""
For i=0 To Ubound(arrPhysicalPath)
If arrPhysicalPath(i)&""<>"" Then
strPath = strPath&arrPhysicalPath(i)&"\"
If Not fso.FolderExists(strPath) Then
'Response.Write("errr")
fso.CreateFolder(strPath)
End If
End If
Next
Set fso = Nothing
End Function
call CheckPath(Server.MapPath("../html/news/ceshi11/"))
HtmlSave "http://"&Application(CacheName&"_WebSetting")(6)&"/news.asp?id="&id,"../html/news/ceshi11/"&id&".htm" '生成html开始
bbsddn 2008-10-22
  • 打赏
  • 举报
回复
我也查了关于FSO的
如何加到我的代码中去呢?我是菜鸟,请高手指点下!
littlelam 2008-10-22
  • 打赏
  • 举报
回复

'检查路径不存在就创建
Public Function CheckPath(physicalPath)
Dim fso,arrPhysicalPath,i,strPath
Set fso = CreateObject("Scripting.FileSystemObject")
arrPhysicalPath = Split(physicalPath,"\")
strPath = ""
For i=0 To Ubound(arrPhysicalPath)
If arrPhysicalPath(i)&""<>"" Then
strPath = strPath&arrPhysicalPath(i)&"\"
If Not fso.FolderExists(strPath) Then
'Response.Write("errr")
fso.CreateFolder(strPath)
End If
End If
Next
Set fso = Nothing
End Function
sy_binbin 2008-10-22
  • 打赏
  • 举报
回复
If Not Fso.FolderExists(strTmpPath) Then
' 创建目录
Fso.CreateFolder(strTmpPath)
End If

Atai-Lu 2008-10-22
  • 打赏
  • 举报
回复

Sub createDir(dirName)
dirName=Server.MapPath(dirName)
set fso=Server.CreateObject("scripting.filesystemobject")
if not fso.folderexists(dirName) then'不存在的时候
set dir=fso.createfolder(dirName)'创建总目录
end if
'fso.close
set fso=nothing
End Sub
'//你直接调用这个过程即可

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧