[英]Batch file to delete files after a certain amount of time in folder?
Is there a way I can create a batch file to delete files from a folder if they are in there for a certain number of days. 有没有一种方法可以创建一个批处理文件,以从文件夹中删除文件(如果它们存在一定天数)。
For example: 例如:
A files is in folder "edited" and has been there for a month, and if a file is in there for a month of longer, the batch file deletes it. 文件位于“已编辑”文件夹中,并且已存在一个月,如果文件已存在一个月以上,则批处理文件将删除该文件。
I'm guessing I would create a batch file then have it run on a schedule to check for files that have been there too long, I just don't know how to write the batch file. 我猜我会创建一个批处理文件,然后让它按计划运行以检查已经存在太长时间的文件,我只是不知道如何编写该批处理文件。
Thanks in advance! 提前致谢!
Googled a little, seems this is the solution: 谷歌一点,似乎这是解决方案:
forfiles -p "c:\your\folder" -s -m *.* /D -<number of days> /C "cmd /c del @path"
Change “C:\\your\\folder” to the directory to which you are saving the files you want to delete on a schedule. 将“ C:\\ your \\ folder”更改为要将计划删除的文件保存到的目录。 Note that the -40 refers to the day after which all files should be deleted so change the -40 if required.
请注意,-40是指应删除所有文件的第二天,因此如果需要,请更改-40。
Have a look at this post Batch file to delete files older than N days 查看此帖子批处理文件以删除N天之前的文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.