Implement files in an automatic Web share folder using the Scheduled tasks and VBS scripts

Source: Internet
Author: User
Tags date definition constant constant definition date1 end implement sort
web| Script

In fact, there is no topic written so complicated, is to use the scheduled task every once in a while to invoke the VBS script, refresh generate a file list file for Web service invocation.

Option Explicit
On Error Resume Next

' The file type of the build list
Const Slistfiletype = "Wmv,rm,wma"

' The relative path where the file is located
Const sshowpath= "."

' Constant definition of sort type
Const iorderfieldfilename = 0
Const Iorderfieldfileext = 1
Const iorderfieldfilesize = 2
Const Iorderfieldfiletype = 3
Const iorderfieldfiledate = 4

' Sort the inverse constant definition
Const IORDERASC = 0
Const IORDERDESC = 1

' Number of files generated in the list
Const ISHOWCOUNT = 20



' The date Format function displayed
Function Cndate2 (Date1,intdatestyle)
Dim strdate,ddate1
Strdate=cstr (Date1)
If Isdate (strdate) Then
If Left (CStr (strdate), 1) = "0" Then
Ddate1=cdate ("+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)) + "Month" +cstr (Day (dDate1)) + "Days"
Case 4:
Cndate2 = CStr (year (dDate1)) + "Years" + Cstr (Month (dDate1)) + "Month" +cstr (Day (dDate1)) + "Days"
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
' Sort
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
' Build list
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 + ("name")
Slistfile = Slistfile + ("</td><td class=pagelisttitletd>")
Slistfile = Slistfile + ("media")
Slistfile = Slistfile + ("</td><td class=pagelisttitletd>")
Slistfile = Slistfile + ("size")
Slistfile = Slistfile + ("</td><td class=pagelisttitletd>")
Slistfile = Slistfile + ("type")
Slistfile = Slistfile + ("</td><td class=pagelisttitletd id=updatetime>")
Slistfile = Slistfile + ("Update Time")
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 + ("<a href= "& Sshowpath &"/"& CStr (Arrfiles ( j,0)) & ">" & Arrfiles (j,0) & "</a>")
If DateDiff ("H", Arrfiles (j,4), now) <=24 then
Slistfile = Slistfile + "End If
Slistfile = Slistfile + "</td><td class=" +stdstyleclass+ ">"
Slistfile = Slistfile + ("<a href=" & Sshowpath & "/" & CStr (Arrfiles (j,0)) & ">")
' Generate Chinese prompts according to filename rules
Select Case Left (Arrfiles (j,0), 3)
Case "SC2":
Slistfile = Slistfile + "<font color= #AA0000 > Sichuan TV"
Case "SD2":
Slistfile = Slistfile + "<font color= #00AA00 > Shandong TV"
Case "GD2":
Slistfile = Slistfile + "<font color= #0000AA > Guangdong TV"
Case "GX2":
Slistfile = Slistfile + "<font color= #AAAA00 > Guangxi TV"
End Select
' Date display
If IsNumeric (Left (Arrfiles (j,0), 8), 2) Then
Imonth = CInt (Left (Arrfiles (j,0), 8), 2)
Iday = CInt (Left (Arrfiles (j,0), 6), 2)
Slistfile = Slistfile + CStr (imonth) + "month" + CStr (iday) + "Day"
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

' The process of generating the calling file
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")

' Compare the last modification time of the calling file and folder
If F.datelastmodified<>f_js. DateLastModified Then
Supdatecontent = ListFile (Slistfiletype,iorderfieldfiledate,iorderdesc,ishowcount)
Set f_js_write = fso. CreateTextFile ("List.js", True)
' JS call adds the following to the 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 ()



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.