- var fso = new ActiveXObject('Scripting.FileSystemObject'),
- dir = 'e:\\javascript',//要删除文件所在的目录
- timer = 120000,//两分钟前创建的文件
- reFile = /^(?:caj|pdf)$/i,//文件格式
- colFiles = new Enumerator(fso.GetFolder(dir).Files),
- file,
- now = new Date();
- for (; !colFiles.atEnd(); colFiles.moveNext()) {
- try {
- file = colFiles.item();
- if (reFile.test(fso.GetExtensionName(file.Name)) && now - new Date(file.DateCreated) > timer) {
- file.Delete();
- }
- } catch (err) {
- WScript.Echo([err.name,err.message].join(' : '));
- }
- }
复制代码
|