vbs怎么实现定时删除功能
本篇内容主要讲解“vbs怎么实现定时删除功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“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.SubFolders
For 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)
loop
getfso=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怎么实现定时删除功能”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341