0

i am trying to create batch file that will delete all files in particular folder mention in batch file. files tha are older then one day deleted from that folder.

My batch file(Daily Files Cleanup) is,

/p "D:\Temporary\PDF" /s /m *.* /c "cmd /c Del @path" /d -1

I took help from this article,

https://www.howtogeek.com/201930/how-to-automatically-delete-files-in-your-download-folder-on-a-schedule/

and Task Scheduler changes to work on daily basis also mention time according to that like 5 minutes after current time in my country

From Events i get result for this batch file,

Task Scheduler successfully finished "{5fb8353e-0136-4110-84bd-83831adadc41}" instance of the "\Daily Files Cleanup"

But all files are still in PDF folder

Hopes for your suggestion i am using win 10

EDITED:

forfiles /p "D:\Temporary\PDF" /s /m *.* /D -1 /C "cmd /c del @path"

This script is working good but deleting all file i want to delete that are created one day ago example today is 19 March files created on 18 March will be deleted not older then that

VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • I would suggest you use `ForFiles` for this, it works better! – Compo Mar 19 '18 at 11:45
  • i changed it to forfiles /p "D:\Temporary\PDF" /s /m *.* /D -1 /C "cmd /c del @path" Now its working .Can i fix it for one day let suppose today is 19 March it just delete files created on 18 March from that folder – syed mohsin Mar 19 '18 at 11:49
  • [Edit your question](https://stackoverflow.com/posts/49361973/edit) title and body, if the initial question was a syntax error and you now have a completely different one. – Compo Mar 19 '18 at 11:52
  • edited my question – syed mohsin Mar 19 '18 at 12:00
  • Possible duplicate of [FORFILES date -after- (date calc in cmd file)](https://stackoverflow.com/questions/19296588/forfiles-date-after-date-calc-in-cmd-file) – aschipfl Mar 19 '18 at 14:42
  • If you haven't got a huge folder content you could try running, e.g. `ForFiles` selecting files older than today which runs `/C "ForFiles command selecting files newer than 2 days ago"`. _(the idea being that only yesterday's files would be chosen)_. If that doesn't work, `RoboCopy` has a facility to select by date and could theoretically be used to delete files. – Compo Mar 19 '18 at 18:24

0 Answers0