欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vbs 定时删除功能实现代码

程序员文章站 2022-03-21 16:40:43
参考代码一:复制代码 代码如下:function deletelog( )    dim objfso, objfolder, strpath...

参考代码一:

复制代码 代码如下:

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