当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbs 定时删除功能实现代码

vbs 定时删除功能实现代码

2017年12月08日  | 移动技术网IT编程  | 我要评论

网络电话平台,生日礼物网站,大学生在线联盟

参考代码一:

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网