利用计划任务和VBS脚本实现自动WEB共享文件夹里的文件
程序员文章站
2022-04-29 09:18:14
复制代码 代码如下:option explicit on error resume next '生成列表的文件类型 const slistfiletype = "wmv,r...
复制代码 代码如下:
option explicit
on error resume next
'生成列表的文件类型
const slistfiletype = "wmv,rm,wma"
'文件所在的相对路径
const sshowpath="."
'排序类型的常量定义
const iorderfieldfilename = 0
const iorderfieldfileext = 1
const iorderfieldfilesize = 2
const iorderfieldfiletype = 3
const iorderfieldfiledate = 4
'排序顺逆的常量定义
const iorderasc = 0
const iorderdesc = 1
'生成列表的文件数量
const ishowcount = 20
'显示的日期格式函数
function cndate2(date1,intdatestyle)
dim strdate,ddate1
strdate=cstr(date1)
if isdate(strdate) then
if left(cstr(strdate),1)="0" then
ddate1=cdate("20"+cstr(strdate))
else
ddate1=cdate(strdate)
end if
else
ddate1=now()
end if
select case intdatestyle
case 1:
cndate2 = cstr(year(ddate1))+"-"+cstr(month(ddate1))+"-"+cstr(day(ddate1))
case 2:
cndate2 = cstr(month(ddate1))+"-"+cstr(day(ddate1))
case 3:
cndate2 = cstr(month(ddate1))+"月"+cstr(day(ddate1))+"日"
case 4:
cndate2 = cstr(year(ddate1))+"年"+ cstr(month(ddate1))+"月"+cstr(day(ddate1))+"日"
end select
end function
function listfile(strfiletype,intcompare,intorder,intshowcount)
dim slistfile
dim fso, f, f1, fc, s,ftype,fcount,i,j,k
dim t1,t2,t3,t4,t5
dim imonth,iday
slistfile = ""
set fso = createobject("scripting.filesystemobject")
set f = fso.getfolder(sshowpath)
set fc = f.files
fcount = fc.count
redim arrfiles(fcount,5)
redim arrfiles2(fcount,5)
i=0
'排序
for each f1 in fc
ftype = right(f1.name,len(f1.name)-instrrev(f1.name,"."))
arrfiles(i,0) = f1.name
arrfiles(i,1) = ftype
arrfiles(i,2) = f1.size
arrfiles(i,3) = f1.type
arrfiles(i,4) = f1.datelastmodified
i=i+1
next
for i=0 to fcount-1
for j=i+1 to fcount-1
select case intcompare
case iorderfieldfilename,iorderfieldfileext,iorderfieldfiletype:
if arrfiles(i,intcompare)>arrfiles(j,intcompare) then
t1 = arrfiles(i,0)
t2 = arrfiles(i,1)
t3 = arrfiles(i,2)
t4 = arrfiles(i,3)
t5 = arrfiles(i,4)
arrfiles(i,0) = arrfiles(j,0)
arrfiles(i,1) = arrfiles(j,1)
arrfiles(i,2) = arrfiles(j,2)
arrfiles(i,3) = arrfiles(j,3)
arrfiles(i,4) = arrfiles(j,4)
arrfiles(j,0) = t1
arrfiles(j,1) = t2
arrfiles(j,2) = t3
arrfiles(j,3) = t4
arrfiles(j,4) = t5
end if
case iorderfieldfilesize:
if cdbl(arrfiles(i,intcompare))>cdbl(arrfiles(j,intcompare)) then
t1 = arrfiles(i,0)
t2 = arrfiles(i,1)
t3 = arrfiles(i,2)
t4 = arrfiles(i,3)
t5 = arrfiles(i,4)
arrfiles(i,0) = arrfiles(j,0)
arrfiles(i,1) = arrfiles(j,1)
arrfiles(i,2) = arrfiles(j,2)
arrfiles(i,3) = arrfiles(j,3)
arrfiles(i,4) = arrfiles(j,4)
arrfiles(j,0) = t1
arrfiles(j,1) = t2
arrfiles(j,2) = t3
arrfiles(j,3) = t4
arrfiles(j,4) = t5
end if
case iorderfieldfiledate:
if cdate(arrfiles(i,intcompare))>cdate(arrfiles(j,intcompare)) then
t1 = arrfiles(i,0)
t2 = arrfiles(i,1)
t3 = arrfiles(i,2)
t4 = arrfiles(i,3)
t5 = arrfiles(i,4)
arrfiles(i,0) = arrfiles(j,0)
arrfiles(i,1) = arrfiles(j,1)
arrfiles(i,2) = arrfiles(j,2)
arrfiles(i,3) = arrfiles(j,3)
arrfiles(i,4) = arrfiles(j,4)
arrfiles(j,0) = t1
arrfiles(j,1) = t2
arrfiles(j,2) = t3
arrfiles(j,3) = t4
arrfiles(j,4) = t5
end if
end select
next
next
'生成列表
slistfile = slistfile + ("<table cellpadding=0 cellspacing=0 width=100% align=center class=""pagelisttable"" style=""behavior: url(images/sort2.htc); "">")
slistfile = slistfile + ("<thead><tr class=pagelisttitletr><td class=pagelisttitletd>")
slistfile = slistfile + ("名称")
slistfile = slistfile + ("</td><td class=pagelisttitletd>")
slistfile = slistfile + ("媒体")
slistfile = slistfile + ("</td><td class=pagelisttitletd>")
slistfile = slistfile + ("大小")
slistfile = slistfile + ("</td><td class=pagelisttitletd>")
slistfile = slistfile + ("类型")
slistfile = slistfile + ("</td><td class=pagelisttitletd id=updatetime>")
slistfile = slistfile + ("更新时间")
slistfile = slistfile + ("</td></tr></thead>")
dim iloopstart,iloofend,iloopstep
if intorder = 0 then
iloopstart = 0
iloofend = fcount-1
iloopstep = 1
else
iloopstart = fcount-1
iloofend = 0
iloopstep = -1
end if
dim icount,stdstyleclass
icount = 1
for j=iloopstart to iloofend step iloopstep
if instr(strfiletype,arrfiles(j,1))>0 and icount<=intshowcount then
stdstyleclass = "pagelisttd"+cstr((icount mod 2)+1)
slistfile = slistfile + ("<tr class=pagelisttr><td class="+stdstyleclass+">")
slistfile = slistfile + ("<img src=images/"+arrfiles(j,1)+".gif align=absbottom><img src=b.gif width=2 height=0><a href=" & sshowpath & "/" & cstr(arrfiles(j,0)) &">" & arrfiles(j,0) &"</a>")
if datediff("h",arrfiles(j,4),now)<=24 then
slistfile = slistfile + "<img src=images/new.gif align=absmiddle>"
end if
slistfile = slistfile + "</td><td class="+stdstyleclass+">"
slistfile = slistfile + ("<a href=" & sshowpath & "/" & cstr(arrfiles(j,0)) &">")
'根据文件名规则,生成中文提示
select case left(arrfiles(j,0),3)
case "sc2":
slistfile = slistfile + "<font color=#aa0000>四川卫视 "
case "sd2":
slistfile = slistfile + "<font color=#00aa00>山东卫视 "
case "gd2":
slistfile = slistfile + "<font color=#0000aa>广东卫视 "
case "gx2":
slistfile = slistfile + "<font color=#aaaa00>广西卫视 "
end select
'日期显示
if isnumeric(left(right(arrfiles(j,0),8),2)) then
imonth = cint(left(right(arrfiles(j,0),8),2))
iday = cint(left(right(arrfiles(j,0),6),2))
slistfile = slistfile + cstr(imonth)+"月" + cstr(iday)+"日"
slistfile = slistfile + ("</a></td><td class="+stdstyleclass+" align=right>")
else
response.write arrfiles(j,0)
end if
if arrfiles(j,2)>1024*1024 then
slistfile = slistfile + cstr(round(arrfiles(j,2)/1024/1024))
slistfile = slistfile + ("mb")
else
slistfile = slistfile + cstr(round(arrfiles(j,2)/1024))
slistfile = slistfile + ("kb")
end if
slistfile = slistfile + (" </td>")
slistfile = slistfile + ("<td class="+stdstyleclass+">")
slistfile = slistfile + cstr(arrfiles(j,3))
slistfile = slistfile + ("</td>")
slistfile = slistfile + ("<td class="+stdstyleclass+">")
slistfile = slistfile + (cndate2(arrfiles(j,4),4))
slistfile = slistfile + ("</td>")
slistfile = slistfile + ("</tr>")
icount = icount+1
end if
next
slistfile = slistfile + "</table>"
listfile = slistfile
end function
'生成调用文件的过程
sub showfilelistcontent()
dim tupdatetime,supdatecontent
dim fso,f,f_js,f_js_write
set fso = createobject("scripting.filesystemobject")
set f = fso.getfolder(sshowpath)
set f_js = fso.getfile("list.js")
'比较调用文件与文件夹的最后修改时间
if f.datelastmodified<>f_js.datelastmodified then
supdatecontent = listfile(slistfiletype,iorderfieldfiledate,iorderdesc,ishowcount)
set f_js_write = fso.createtextfile("list.js", true)
'js调用就加上下面这对document.write
' f_js_write.write ("document.write('")
f_js_write.write (supdatecontent)
' f_js_write.write ("')")
f_js_write.close
end if
end sub
call showfilelistcontent()
上一篇: 用vbs实现cmd功能的代码
下一篇: VBS如何察看或获得剪切板内容的脚本