Could you please help me with a command for batch file to delete the files with Name of the file.
I need to delete the files which are older than 6 months according to their File name. I need to schedule the script in Task scheduler, So it will delete the files in specific location every day which are older than 6 months from current date according to their file name.
Location of files:
K:\Bck
File Names:
Backup_2020-10-22.txt
Backup_2020-10-21.txt
Backup_2019-09-16.txt
Backup_2018-05-17.txt
Backup_2017-04-16.txt
Here is a modified version of
Aacini's
post, from back in 2013. I only amended it to usepowershell
to get today's date, instead of using the locale specific%date%
variable and some changes to accomodate your environment. So I take no credit for this whatsoever.This will NOT yet delete anything. It will simply echo the commands to the screen. If you are sure the
echo
'd results resemble what you want, you can remove theecho
from the lineecho del "%%a_%%b_%%c_%%d" /Q
You also need to set your days accordingly in the line
if !daysOld! gtr 180 (