ASP生成静态HTML,可任意深度路径的函数

< %
	set FSO = Server.CreateObject("Scripting.FileSystemObject")

	Function CheckFile(byval Path)
		pathArr = Split(Path,"/")
		Path = replace(Path,"/" & pathArr(ubound(pathArr)),"")
		if Path = "" then Exit Function
		if not FSO.FolderExists(Server.Mappath(Path)) then
			Call CheckFile(Path)
			FSO.CreateFolder(Server.Mappath(Path))
		end if
	End Function

	Function newFile(byval Path)
		if Right(Path,1)="/" then
			Path = Path & "index.html"
		end if
		Call CheckFile(Path)
		Set newFile = FSO.CreateTextFile(Server.Mappath(Path))
	End Function

	set n = newFile("/index/cat2/path/demo/111/222/333/444/555/666/777/888/")
	n.write "12345"
	n.close
	set n = nothing

	set n = newFile("../../../../test.css")
	n.write "body{}"
	n.close
	set n = nothing
%>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.