vbs 定时删除功能实现代码
来源:易贤网 阅读:931 次 日期:2014-08-12 12:20:01
温馨提示:易贤网小编为您整理了“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

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
易贤网手机网站地址:vbs 定时删除功能实现代码
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标