简体   繁体   中英

delete files older than 90 days using batch file

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

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

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

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"

For your example, not specifying a path:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM