计划任务:使用Windows批处理脚本清理目录

时间:2022-10-28 02:22:36

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服务器的批处理脚本解决方案(不确定是哪个版本)?

4 个解决方案

#1


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-文件 - 即 - 是 - 一个指定用户号码的-小时old.aspx

#2


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.

删除路径也可以作为参数发送到此批处理脚本,以便目录可更改。

#3


I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.

我最后只写了一个接受参数和调度的EXE。不幸的是,其他解决方案没有所需的灵活性。

#4


have you looked into forfiles.exe?

你看过forfiles.exe吗?

http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/

#1


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-文件 - 即 - 是 - 一个指定用户号码的-小时old.aspx

#2


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.

删除路径也可以作为参数发送到此批处理脚本,以便目录可更改。

#3


I ended up just writing an EXE that accepts parameters and scheduling that. Unfortunately the other solutions didn't have the flexibility needed.

我最后只写了一个接受参数和调度的EXE。不幸的是,其他解决方案没有所需的灵活性。

#4


have you looked into forfiles.exe?

你看过forfiles.exe吗?

http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/