利用计划任务和VBS脚本实现自动WEB共享文件夹里的文件
来源:本站原创|时间:2020-01-10|栏目:vb|点击: 次
复制代码 代码如下:
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引用另一个vbs的代码
栏 目:vb
本文标题:利用计划任务和VBS脚本实现自动WEB共享文件夹里的文件
本文地址:https://www.xiuzhanwang.com/a1/vb/7625.html
您可能感兴趣的文章
- 01-10利用WSH里的MapNetworkDrive方法脚本蠕虫的传播方式
- 01-10利用vbscript脚本修改文件内容,此适用于自动化的操作中
- 01-10利用VBS脚本自动创建计算机帐户的代码
- 01-10利用wscript执行文件[包括可执行exe文件]vbs脚本
- 01-10如何使用脚本锁定任务栏?
- 01-10利用vbs脚本实现设置IE的打印页眉页脚信息
- 01-10利用VBS脚本轻松盗U盘数据
- 01-10两个vbs脚本利用了wscirpt.network
- 01-10vbscript脚本编程教程2利用fso来进行文件操作
- 01-10利用vbs类实现css按钮的代码
阅读排行
本栏相关
- 01-10下载文件到本地运行的vbs
- 01-10飘叶千夫指源代码,又称qq刷屏器
- 01-10SendKeys参考文档
- 01-10什么是一个高效的软件
- 01-10VBS中的正则表达式的用法大全 &l
- 01-10exe2swf 工具(Adodb.Stream版)
- 01-10VBS中SendKeys的基本应用
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript教程 第十一课深入VBScript
- 01-10VBScript语法速查及实例说明
随机阅读
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10C#中split用法实例总结
- 01-10SublimeText编译C开发环境设置
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 04-02jquery与jsp,用jquery
- 01-10delphi制作wav文件的方法
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11ajax实现页面的局部加载