‘vbs 删除目录下文件创建日期大于7天的文件 dim AllPathFileName ‘所有输出的文件路径 dim fs ‘操作文件对象 dim foldername ‘要删除的目录路径 dim nowTime nowTime=Now() ‘当前时间 foldername =Array("D:\Helka\TestBak\","D:\Helka\Test222\") ‘多个目录在这里添加 Set fs = CreateObject("scripting.filesystemobject") For i=0 to UBound(foldername) digui (foldername(i))‘调用函数进行查找 Next msgbox AllPathFileName ‘结果显示 ‘下面是递归查找函数 Function digui(path) Set folder = fs.getfolder(path) Set subfolders = folder.subfolders Set Files = folder.Files For Each file In Files AllPathFileName=AllPathFileName & file.path ‘找到则追加到变量FileName中 ‘AllPathFileName=AllPathFileName& file.name & file.DateCreated&"__"& file.DateLastModified&"__"& file.DateLastAccessed&"__"& DayCount & vbNewLine dim DayCount DayCount=DateDiff("d",file.DateCreated,nowTime) If DayCount>7 Then fs.deleteFile(file.path) ‘删除这个文件 AllPathFileName=AllPathFileName& "__DELETE" else AllPathFileName=AllPathFileName& "__NOT" End If AllPathFileName=AllPathFileName & vbNewLine Next ‘For Each j In subfolders ‘ digui (j.path) ‘递归查找子目录 ‘Next End Function
原文:https://www.cnblogs.com/q149072205/p/12295495.html