I have Windows 8.1 & Firefox Latest.
I want to create a Cmd file, which can delete all files in target folders/sub folders earlier than 15 days. This Cmd file is needed to run every day.
https://drive.google.com/file/d/0B1calHz69fSuRzNKb214ajkxM2c/view?ts=5925e6a9
Is it possible ? IF yes, Kindly post sample Cmd Script.
Thanks in advance.
Deleting Files datewise
Moderator: DosItHelp
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Deleting Files datewise
Earlier than 15 days? Today is the 24th, fifteen days ago was the 9th. If I ran the script today, would you expect files from the 8th to be deleted, or would you expect files from the 10th to be deleted?
-
- Posts: 18
- Joined: 23 Apr 2017 22:36
Re: Deleting Files datewise
I was meaning older than 15 days on the date of run. In other words, today I have files from Jan 1, 2017. If I run Cmd file today, files 15 older be deleted as on today. When I run same Cmd file on June1, 2017, files older than that date be deleted. I hope I clarified.
Thank you in advance, for responding ShadowThief Sir.
Thank you in advance, for responding ShadowThief Sir.
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Deleting Files datewise
This will list files
once you know its ok
To run every day, create a task
Code: Select all
forfiles -p "C:\what\ever\dir" -s -m *.* -d -15 -c "cmd /c echo @path"
once you know its ok
Code: Select all
forfiles -p "C:\what\ever\dir" -s -m *.* -d -15 -c "cmd /c del @path"
To run every day, create a task
Code: Select all
schtasks /create /SC DAILY /ST "04:00" /TN "your-task-name" /RL HIGHEST /TR "your-script-path-plus-name" /F
-
- Posts: 18
- Joined: 23 Apr 2017 22:36
Re: Deleting Files datewise
elzooilogico Sir,
I am going to try all that you explained and it looks lovely. Pleas approve then I shall run these files.
1. Created D:\Cmd\List.Cmd
2.Created D:\Cmd\Confirm.Cmd
3.Created D:\Cmd\Schedule.Cmd
One more Sir, do I need to run D:\Cmd\Schedule.Cmd just once or daily.
Kindly confirm or suggest edit.
Thanks tons Sir.
I shall be ever grateful to you Sir.
I am going to try all that you explained and it looks lovely. Pleas approve then I shall run these files.
1. Created D:\Cmd\List.Cmd
Code: Select all
forfiles -p "D:\Instal" -s -m *.* -d -15 -c "cmd /c echo @E:\Instal"
rem forfiles -p "C:\what\ever\dir" -s -m *.* -d -15 -c "cmd /c echo @path"
2.Created D:\Cmd\Confirm.Cmd
Code: Select all
forfiles -p "D:\Instal" -s -m *.* -d -15 -c "cmd /c echo @E:\Instal"
rem forfiles -p "C:\what\ever\dir" -s -m *.* -d -15 -c "cmd /c echo @path"
3.Created D:\Cmd\Schedule.Cmd
Code: Select all
schtasks /create /SC DAILY /ST "10:00" /TN "Delete&update" /RL HIGHEST /TR "D:\Cmd\Delete.Cmd" /F
rem schtasks /create /SC DAILY /ST "04:00" /TN "your-task-name" /RL HIGHEST /TR "your-script-path-plus-name" /F
One more Sir, do I need to run D:\Cmd\Schedule.Cmd just once or daily.
Kindly confirm or suggest edit.
Thanks tons Sir.
I shall be ever grateful to you Sir.
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Deleting Files datewise
your file (i.e D:\cmd\deleteTask.cmd) should look like
@path is a `forfiles` special word that tells the command to use the full path\filename of all files matching the condition given.
see forfiles /? to get help on switches.
You don`t need more batch files.
Schtask is the command to create an scheduled task, you can run it in the command line.
So, with the batch file newly created simply execute this in the command line
EDIT and WARNING
But before doing this, I suggest you run the following in command line to test if the condition grabs exactly what you want.
Code: Select all
forfiles -p "D:\Instal" -s -m *.* -d -15 -c "cmd /c del @path"
@path is a `forfiles` special word that tells the command to use the full path\filename of all files matching the condition given.
see forfiles /? to get help on switches.
You don`t need more batch files.
Schtask is the command to create an scheduled task, you can run it in the command line.
So, with the batch file newly created simply execute this in the command line
Code: Select all
schtasks /create /SC DAILY /ST "10:00" /TN "Delete&update" /RL HIGHEST /TR "D:\cmd\deleteTask.cmd" /F
EDIT and WARNING
But before doing this, I suggest you run the following in command line to test if the condition grabs exactly what you want.
Code: Select all
forfiles -p "D:\Instal" -s -m *.* -d -15 -c "cmd /c echo @path @fdate"