Page 1 of 1
Deleting Files datewise
Posted: 24 May 2017 14:15
by sajjansinghania
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=5925e6a9Is it possible ? IF yes, Kindly post sample Cmd Script.
Thanks in advance.
Re: Deleting Files datewise
Posted: 24 May 2017 15:47
by ShadowThief
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?
Re: Deleting Files datewise
Posted: 24 May 2017 23:39
by sajjansinghania
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.
Re: Deleting Files datewise
Posted: 25 May 2017 03:56
by elzooilogico
This will list files
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
Re: Deleting Files datewise
Posted: 25 May 2017 04:44
by sajjansinghania
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
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.
Re: Deleting Files datewise
Posted: 25 May 2017 05:09
by elzooilogico
your file (i.e
D:\cmd\deleteTask.cmd) should look like
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 WARNINGBut 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"