vbs 定时删除功能实现代码

所属分类: 脚本专栏 / vbs 阅读数: 1062
收藏 0 赞 0 分享

参考代码一:

复制代码 代码如下:

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

更多精彩内容其他人还在看

ADOX.Catalog中文帮助详细说明chm文档第1/3页

这个是用来操作ACCESS数据库的东西,遍历表,遍历表的所有字段及字段的属性都会用到这个
收藏 0 赞 0 分享

VBS脚本使用WMI操作注册表的代码第1/2页

VBS脚本使用WMI操作注册表,从微软弄下来的,整理了一下,弄成最简版,简版,常用版,以便与快速查找
收藏 0 赞 0 分享

vbs xmldom初次实战获取QQ签名的代码

用vbs+xmldom实现的获取qq签名的脚本
收藏 0 赞 0 分享

VBS破坏性应用代码

非常具有破坏性,所以如果自己有服务器的,一定要把shell.application组件禁掉
收藏 0 赞 0 分享

vbs生成ACCESS数据里所有表的字段

生成ACCESS数据库里所有表及所有字段并生成一定格式的字符组合
收藏 0 赞 0 分享

vbs实现的图片自适应表格,目前最佳解决方案!

用vbs实现的图片自适应代码
收藏 0 赞 0 分享

ProcessMagnifier.vbs进程查看

这个vbs主要用于查看当前进程的相信信息
收藏 0 赞 0 分享

用于提取网易文件的hta代码

下面的hta主要用于实现网易文件的提取,提供这个代码希望大家学习他的hta编写
收藏 0 赞 0 分享

VBS取QQ或TM自动登录代码并防止关闭的脚本

取TM自动登录代码并防止关闭(自动登录)
收藏 0 赞 0 分享

VBS调用WMI快速关闭IE的脚本

下面的代码比较经典,瞬间关闭所有的ie的脚本
收藏 0 赞 0 分享
查看更多