本程序是为了删除目录下的在一定时间内没有被访问的文件和文件夹,采用递归方法,有两个程序Autodelete.bat和Autodelete.js。具体如下:
Autodelete.bat:
@echo off
For /F "token=1,2,3 delims=-" %%i IN ('DATE /T') DO SET file=.\logs\%%i-%%j-%%
k.log
cscript Autodelete.js >>%%file%
Autodelete.js
function Autodelete(folderspc,level){
var fso,f,fc,s,i=0;
fso = new ActiveXobject("Scripting.FilesystemObject");
fc = new Enumerator(f.files);
var d = new Date();
s = "";
for(;!fc.atEnd();fc.moveNext())
{
k=fso.GetFile(fc.item());
var h = new Date(k.DateLastAccessed);
if(d.getTime()-h.getTime())>259200000 \\超过三天
{
Wscript.echo(fc.item()) +"\n" +d.getTime()-h.getTime())+"\n";
fso.DeleteFile(fc.item());
i++;
}
fc = new Enumerator(f.subfolders);
for(;!fc.atEnd();fc.movenext())
{
Autodelete(fc.itme(),"subfolder");
i++;
}
h = new Date(f.DateLastAccessed);
if ((i==0)&&((d.getTime()-h.getTime())>259200000 )&&(level=="subfolder")
{
wscript.echo(folderspec+""+d.getTime()-h.getTime()+"\n");
fso.DeleteFolder(folderspec);
}
}
Autodelete("e:\\test";"parefolder");
}
阅读(2509) | 评论(0) | 转发(0) |