欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

自动删除超过10天的文件及文件夹的vbs代码

程序员文章站 2022-04-10 08:12:51
复制代码 代码如下:option explicit dim fpath,fso,logfile,fwrite fpath=inputbox ("输入目标文件夹","文件处理...
复制代码 代码如下:

option explicit
dim fpath,fso,logfile,fwrite
fpath=inputbox ("输入目标文件夹","文件处理器")
logfile="logfile.txt"
set fso=createobject("scripting.filesystemobject")
set fwrite=fso.opentextfile(logfile,8,true)
getfilename fpath
fwrite.close
set fso=nothing
msgbox "命令执行完成!"
function getfilename(path)
dim file,folder,sfolder,fname,subfolder,files
if not fso.folderexists(path) then
set fso=nothing
msgbox "目标文件夹不存在!"
exit function
end if
set folder=fso.getfolder(path)
set files=folder.files
for each file in files
fwrite.writeline path&"\"&file.name
if file.datelastmodified < now - 10 then '判断是否超过10天
fso.deletefile(file)
'wscript.echo file
end if
next
set subfolder=folder.subfolders
for each sfolder in subfolder
fwrite.writeline path&"\"&sfolder.name
if sfolder.datecreated < now - 10 then '判断是否超过10天
fso.deletefolder(sfolder)
'wscript.echo file
end if
next
end function

将上面代码存为vbs文件即可使用。