|
|
本帖最后由 将脚本进行到底 于 2013-5-5 01:31 编辑
先解释一下,主程序是个定时功能,子程序是遍历和删除的功能,遍历采用的是递归调用!
--------------------------------------------------开始--------------------------------------------------------------
On Error Resume Next
dim k,m,a,b,b1,d1
dim t1,t2,t3,t4,t5,t6
---------------------------------------定时-----------------------------------------------------------
t4=inputbox("请指定删除系统垃圾的时间(格式为xx:xx:xx: ) ")
if t4<>""then
t5=cdate(t4)
t2=inputbox("请指定删除系统垃圾的日期(格式是xxxx年/xx月/xx日)")
if t2<>" "then
t3=cdate(t2)
t1=date
if t3=t1 then
do
t6=time
loop until t6=t5
if t6=t5 then
set s1=wscript.createobject("wscript.shell")
bianli("c:\")
if m<>0 then
s1.popup "共删除了"&m&"个系统垃圾文件",2,"提示",64
end if
end if
else
end if
else
end if
else
end if
-----------------------------------------------------------遍历--------------------------------------------------------------
function bianli(spath)
set ofso=createobject("scripting.filesystemobject")
set ofolder=ofso.getfolder(spath)
set osubfolders=ofolder.subfolders
set ofiles=ofolder.files
----------------文件的遍历---------------------
for each ofile in ofiles
--------------文件判断和删除-------------------
b=ofile.name
k=right(b,4)
if k=".tmp" or k=".log" or k=".gid" or k="chk" or k=".old" or k=".bak" then
ofso.deletefile(ofile)
m=m+1
end if
next
----------------文件夹的遍历---------------------
for each osubfolder in osubfolders
b1=osubfolder.path
bianli(osubfolder.path)
next
set ofolder=nothing
set osubfolders=nothing
set ofso=nothing
end function
---------------------------------------------结束------------------------------------------------------
我发现一些问题,如果这个程序没有到定时触发点,那就意味着一直处于循环判断中,可是在xp上跑,发现它一直占用很多CPU的使用资源,而且PC会变得非常的卡,我不知道是XP操作系统分配资源的问题,还是VBS本来就是如此!
所以想问下VBS有没有分配资源的权限?如果没有,是不是只能通过调用API来实现? |
|