使用批处理文件删除6个月以上的文件 [英] Delete files older than 6 months with batch file

查看:89
本文介绍了使用批处理文件删除6个月以上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须删除6个月以上的tmp文件.我在批处理文件中运行了此命令,该命令删除了早于180天的文件.

I have to delete tmp files that are older than 6 months. I have this command runing in the batch file which delete files older than 180 days.

forfiles /p "C:\Backup" /s /m *.tmp /c "cmd /c Del @path" /d -180

,但我想传递number of month而不是number of days.任何想法都会大有帮助.预先感谢

but I want to pass number of month instead of number of days. any idea would be greatly helpful. Thanks in advance

推荐答案

如果您确实想提供日,月,年中的任何一个作为参数,则也可以使用powershell命令.

You could also use powershell commands if you really want to provide day, month, year any of these as an argument.

示例:

Get-ChildItem –Path  "C:\Backups" –Recurse | Where-Object CreationTime –lt (Get-Date).AddMonths(-6) | Remove-Item

这篇关于使用批处理文件删除6个月以上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆