计划任务:使用 Windows 批处理脚本进行目录清理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/429567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scheduled Task: Directory cleanup using windows batch script
提问by Joe Phillips
I have a shared disk that I would like to clean up once per week using a scheduled task of some sort. I would like to use a batch script so that the system admins can easily modify it or reuse it on other directories when needed.
我有一个共享磁盘,我想使用某种计划任务每周清理一次。我想使用批处理脚本,以便系统管理员可以在需要时轻松修改它或在其他目录上重用它。
The directory has files with multiple file extensions but the ones that need to be deleted end in .bkf and must be over 2 weeks old.
该目录包含具有多个文件扩展名的文件,但需要删除的文件以 .bkf 结尾,并且必须超过 2 周。
Does anyone have a batch script solution for this windows server (not sure which version)?
有没有人有这个 Windows 服务器的批处理脚本解决方案(不确定哪个版本)?
采纳答案by Joe Phillips
I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.
我最终只是编写了一个接受参数并对其进行调度的 EXE。不幸的是,其他解决方案没有所需的灵活性。
回答by Austin Salonen
If you have PowerShell (or can install it), check out this link: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-old.aspx
如果您有 PowerShell(或可以安装),请查看此链接: http://thepowershellguy.com/blogs/posh/archive/2007/12/13/hey-powershell-guy-how-can-i-delete-files-that-are-a-specified-number-of-hours-旧的.aspx
回答by CheeseConQueso
Take a look at this page - scheduling tasks from command line
看看这个页面 -从命令行调度任务
It shows you hot to create scheduled tasks from the command line. You might be able to use this in combination with other dos commands to get your result.
它向您展示了从命令行创建计划任务的热点。您可以将它与其他 dos 命令结合使用来获得结果。
The only thing that needs to be in the batch file is
批处理文件中唯一需要的是
@echo off
cls
del C:\some\directory\*.bkf
And the delete path can also be sent to this batch script as an argument so that the directory is changeable.
并且删除路径也可以作为参数发送到这个批处理脚本,以便目录是可变的。
回答by phill
have you looked into forfiles.exe?
你看过 forfiles.exe 吗?
http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/
http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/