使用批处理文件删除超过90天的文件

时间:2023-01-15 10:28:16

I want to delete *.sql files older than 90 days using batch file and I wrote following command.

我想使用批处理文件删除超过90天的* .sql文件,我写了以下命令。

forfiles /M *.sql /d -90 /c "cmd /c del @file

I am not sure above command is valid? and if not need suggestions.

我不确定上面的命令是否有效?如果不需要建议。

1 个解决方案

#1


0  

forfiles /M *.sql /d -90 /c "cmd /c del @file

forfiles / M * .sql / d -90 / c“cmd / c del @file

SYNTAX (FOR WIN XP FORFILES RESOURCE KIT)
FORFILES [-p Path] [-m Mask] [-s] [-c Command] [-d [+ | -] {dd/MM/yyyy | dd}]

You haven't specified a path, so it will default to your current directory. Also, you didn't close out the quotes at the end of your command. For the sake of safety, I would specify your path.

您尚未指定路径,因此它将默认为您当前的目录。此外,您没有在命令末尾关闭引号。为了安全起见,我会指定你的路径。

forfiles -p"C:\Path\To\sqlfiles" -m *.sql -d-90 -c"cmd /c del @FILE"

forfiles -p“C:\ Path \ To \ sqlfiles”-m * .sql -d-90 -c“cmd / c del @FILE”

For your example, not specifying a path:

对于您的示例,不指定路径:

forfiles -m *.sql -d-90 /c"cmd /c del @FILE"

forfiles -m * .sql -d-90 / c“cmd / c del @FILE”

EDIT: Edited my command as using / instead of - for the switch symbols doesn't work. Removed the link as well because it stated otherwise. Please note: do not insert spaces between the switch and inputs as it will fail. Also, your @ parameter must be in all caps. Also to note, the online documentation on ss64.com is incorrect for the usage of @PATH

编辑:编辑我的命令为使用/而不是 - 因为开关符号不起作用。删除了链接,因为它另有说明。请注意:请勿在开关和输入之间插入空格,因为它会失败。此外,您的@参数必须全部大写。另请注意,ss64.com上的在线文档对于@PATH的使用不正确

#1


0  

forfiles /M *.sql /d -90 /c "cmd /c del @file

forfiles / M * .sql / d -90 / c“cmd / c del @file

SYNTAX (FOR WIN XP FORFILES RESOURCE KIT)
FORFILES [-p Path] [-m Mask] [-s] [-c Command] [-d [+ | -] {dd/MM/yyyy | dd}]

You haven't specified a path, so it will default to your current directory. Also, you didn't close out the quotes at the end of your command. For the sake of safety, I would specify your path.

您尚未指定路径,因此它将默认为您当前的目录。此外,您没有在命令末尾关闭引号。为了安全起见,我会指定你的路径。

forfiles -p"C:\Path\To\sqlfiles" -m *.sql -d-90 -c"cmd /c del @FILE"

forfiles -p“C:\ Path \ To \ sqlfiles”-m * .sql -d-90 -c“cmd / c del @FILE”

For your example, not specifying a path:

对于您的示例,不指定路径:

forfiles -m *.sql -d-90 /c"cmd /c del @FILE"

forfiles -m * .sql -d-90 / c“cmd / c del @FILE”

EDIT: Edited my command as using / instead of - for the switch symbols doesn't work. Removed the link as well because it stated otherwise. Please note: do not insert spaces between the switch and inputs as it will fail. Also, your @ parameter must be in all caps. Also to note, the online documentation on ss64.com is incorrect for the usage of @PATH

编辑:编辑我的命令为使用/而不是 - 因为开关符号不起作用。删除了链接,因为它另有说明。请注意:请勿在开关和输入之间插入空格,因为它会失败。此外,您的@参数必须全部大写。另请注意,ss64.com上的在线文档对于@PATH的使用不正确