Hi, think this is the right forum?! I have a classic ASP script that works a treat to calculate directory sizes and write them back to a database, code below. The problem I have is I need to run the script in task scheduler on Windows server which you can't do with a .asp file. Apparently a .vbs file will.
Anyone know how I get this script to work and to be able to test it out?
Thanks for looking. (Raw ASP below)
Anyone know how I get this script to work and to be able to test it out?
Thanks for looking. (Raw ASP below)
Code:
<%
Dim connStrmpro
Set connStrmpro = Server.CreateObject("ADODB.Connection")
'connStr.Open "Provider=SQLOLEDB; Data Source = (CONCISE-HOST3\SQLEXPRESS); Initial Catalog = wce_site; User Id = sa; Password=concise"
connStrmpro.Open "PROVIDER=SQLOLEDB;DATA SOURCE=10.1.1.1,1433;UID=sa;PWD=password;DATABASE=mysite_db"
'Option explicit
dim fso
dim objlogfile
dim objFolder
dim s
dim showfoldersize
dim dataFolder
dim colSubfolders
dim strsubfolders
dim objsubfolder
dim myDay
Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
else
pd = n
end if
End Function
'Get Current DAte and Time
myDay = YEAR(Date()) & _
"/" & Pd(Month(date()),1) & _
"/" & Pd(DAY(date()),1)
myDay = myDay& " "&time()
Set dctSizes = CreateObject("Scripting.Dictionary")
dctSizes.Add 1073741824, " GB"
dctSizes.Add 1048576, " MB"
dctSizes.Add 1024, " KB"
dctSizes.Add 0, " Bytes"
set fso=createobject("scripting.filesystemobject")
Set objFolder = fso.GetFolder("e:\web\")
Set colsubfolders = objFolder.subfolders
For each objsubfolder in colSubfolders
intSize = objsubfolder.size
For Each intThreshold In dctSizes
If intSize > intThreshold Then
strSize = Round(intSize / intThreshold, 2)
strSize = strSize & dctSizes(intThreshold)
Exit For
End If
Next
qryinsnewlist = "INSERT INTO wce_dir_sizes (dir, size, serverip, recordedtime, day, month, year) VALUES (('"& (objsubfolder.name) &"'), ('"& (strSize) &"'), ('"& ("185.3.164.27") &"'), ('"& (myDay) &"'), ('"& (Day(date)) &"'), ('"& (Month(date)) &"'), ('"& (Year(date)) &"'))"
'response.write(qryinsnewlist)
Set oRsinsnewlist = connStrmpro.Execute(qryinsnewlist)
Next
%>