Hi i am relatively new to windows service. I want to create a schedule task that will go through certain folder like c://dev/ and delete the files that are created between some date/time. How can i achieve this?Any help really appriciated...
-
Do you really need to make a service for this? A simple batch file run by the Windows Scheduler should do the job. – paddy Mar 12 '13 at 04:13
-
Do you want to create windows service that does something (i.e. delete files) OR you want to delete files (i.e. by using windows service) - these questions are very different, but it is unclear which one you wanted to ask. – Alexei Levenkov Mar 12 '13 at 04:13
-
Sorry Alexei I want to create windows service that deletes files. – Mar 12 '13 at 04:18
2 Answers
Check this for 'forfiles' command: Batch file to delete files older than N days
Then you can store a command of your wish into a .bat file and set Windows Task Scheduler to run that file.
If you want to do it using Windows Services, check this: http://www.c-sharpcorner.com/blogs/7224/deleting-a-file-after-7-days-using-windows-services.aspx
If you want to run a custom scheduler from a windows service, you can try out the Quartz open source scheduling service library. You can then define CRON Triggers to fire as and when you need. I have used this in a windows service developed in C# and its excellent. The tutorials will quickly get you up and running.
For the windows service itself, you can have a look at the article by @mostruash above or even this. You can easily customize the base templates as per your wishes.

- 3,491
- 2
- 22
- 39