Hi Guys. I will share how to delete files in the x days folder ago. this will be boring if done by humans. So, we can delegate this repeat job to a computer machine. Lets practice delete older file windows.
This will be useful when we will delete the daily backup file.
I use CMD Command Prompt
and run the FORFILES command.
FORFILES /p "D:\DB-BACKUP" /m *.* /c "cmd /c Del /F /Q @path" /d -14 /
The parameters we can use are as follows:
/S - This switch makes forfiles recurse subdirectories. Like "DIR /S". /D - Select files with a last modified date. For example,-365 means over a year ago, -30 means a month ago. /P - To indicate the path to start the search. /C "command" - This command specifies the command to execute on each file that will be found. Command strings should be wrapped in double quotes.
The default command is “cmd /c echo @file”.
The following variables can be used in the command string:
- @file – returns the name of the file.
- @fname – returns the file name without extension.
- @ext – returns only the extension of the file.
- @path – returns the full path of the file.
- @relpath – returns the relative path of the file.
- @isdir – returns “TRUE” if a file type is a directory, and “FALSE” for files.
- @fsize – returns the size of the file in bytes.
- @fdate – returns the last modified date of the file.
- @ftime – returns the last modified time of the file.
This is simple, you can modified this command what’s you need. like scheduler.