<%
dim thetime
dim thename
dim theyear
dim themonth
dim thedate
dim thehour
dim theminute
dim thesecond
'取得时间中各数值
thetime=now()
theyear=year(now())
themonth=month(now())
thedate=day(now())
thehour=hour(now())
theminute=minute(now())
thesecond=second(now())
'检查数值
if len(theyear)=2 then
theyear="20" & theyear
end if
call che(themonth)
call che(thedate)
call che(thehour)
call che(theminute)
call che(thesecond)
'生成随机数
randomize
sjs=rnd*(9999)
call chernd(sjs)
thedir=theyear & themonth & thedate
thename=theyear & themonth & thedate & thehour & theminute & thesecond & sjs & ".htm"
'准备生成文件
top="<html><head><title>news</title></head><body>"
botom="</body></html>"
msg=request.Form("msg")
msg="现在时间是:"&now() '由于没有做表单,所以先用时间作写入内容,有表单提交后这里须删除
msg=replace(msg,vbcrlf,"")
msg=replace(msg,chr(9),"")
msg=replace(msg," "," ")
msg=replace(msg,"\r\n","<br>")
msg=replace(msg,"\n","<br>")
msg=top&msg&botom
''===检查文件夹和文件===
Set fs=Server.CreateObject("Scripting.FileSystemObject")
new_tree=server.mappath("new")
if (fs.FolderExists(new_tree)) then'判断new文件夹是否存在
else
fs.CreateFolder(new_tree)
end if
day_tree=server.mappath("new") & "\" & thedir
if (fs.FolderExists(day_tree)) then'判断今天的文件夹是否存在
else
fs.CreateFolder(day_tree)
end if
che_file=server.mappath("new") & "\" & thedir & "\" & thename
if (fs.FileExists(che_file)) then '判断thename文件是否存在,防重名
fs.close
set fs=nothing
%>
<script language="javascript">
alert("文件重名,请返回重新生成!")
history.back();
</script>
<%
end if
''===开始生成===
thefilename=thename
thefilename=thefilename
filez=day_tree & "\" & thefilename
set ts = fs.createtextfile(filez,true) '写文件
for z=1 to len(msg)
write_now=mid(msg,z,1)
ts.write(write_now)
next
ts.close
set ts=nothing '文件生成成功
if err.number<>0 or err then
response.write "文件生成失败!"
else
response.write "文件生成成功!"
response.write "<br><br>"
response.write " 文件名为:" & thename
end if
'检查数值函数
function che(x)
if len(x)<2 then x="0" & x
end function
function chernd(x1)
'检查随机数数值函数,去小数点
for i=1 to len(x1)
if mid(x1,i,1)<>"." then
x2=x2 & mid(x1,i,1)
end if
next
x1=x2
end function
%>
dim thetime
dim thename
dim theyear
dim themonth
dim thedate
dim thehour
dim theminute
dim thesecond
'取得时间中各数值
thetime=now()
theyear=year(now())
themonth=month(now())
thedate=day(now())
thehour=hour(now())
theminute=minute(now())
thesecond=second(now())
'检查数值
if len(theyear)=2 then
theyear="20" & theyear
end if
call che(themonth)
call che(thedate)
call che(thehour)
call che(theminute)
call che(thesecond)
'生成随机数
randomize
sjs=rnd*(9999)
call chernd(sjs)
thedir=theyear & themonth & thedate
thename=theyear & themonth & thedate & thehour & theminute & thesecond & sjs & ".htm"
'准备生成文件
top="<html><head><title>news</title></head><body>"
botom="</body></html>"
msg=request.Form("msg")
msg="现在时间是:"&now() '由于没有做表单,所以先用时间作写入内容,有表单提交后这里须删除
msg=replace(msg,vbcrlf,"")
msg=replace(msg,chr(9),"")
msg=replace(msg," "," ")
msg=replace(msg,"\r\n","<br>")
msg=replace(msg,"\n","<br>")
msg=top&msg&botom
''===检查文件夹和文件===
Set fs=Server.CreateObject("Scripting.FileSystemObject")
new_tree=server.mappath("new")
if (fs.FolderExists(new_tree)) then'判断new文件夹是否存在
else
fs.CreateFolder(new_tree)
end if
day_tree=server.mappath("new") & "\" & thedir
if (fs.FolderExists(day_tree)) then'判断今天的文件夹是否存在
else
fs.CreateFolder(day_tree)
end if
che_file=server.mappath("new") & "\" & thedir & "\" & thename
if (fs.FileExists(che_file)) then '判断thename文件是否存在,防重名
fs.close
set fs=nothing
%>
<script language="javascript">
alert("文件重名,请返回重新生成!")
history.back();
</script>
<%
end if
''===开始生成===
thefilename=thename
thefilename=thefilename
filez=day_tree & "\" & thefilename
set ts = fs.createtextfile(filez,true) '写文件
for z=1 to len(msg)
write_now=mid(msg,z,1)
ts.write(write_now)
next
ts.close
set ts=nothing '文件生成成功
if err.number<>0 or err then
response.write "文件生成失败!"
else
response.write "文件生成成功!"
response.write "<br><br>"
response.write " 文件名为:" & thename
end if
'检查数值函数
function che(x)
if len(x)<2 then x="0" & x
end function
function chernd(x1)
'检查随机数数值函数,去小数点
for i=1 to len(x1)
if mid(x1,i,1)<>"." then
x2=x2 & mid(x1,i,1)
end if
next
x1=x2
end function
%>
回复Comments
作者:
{commentrecontent}