问题
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...
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/15353160/how-to-create-a-windows-service-to-schedule-some-task-like-delete-the-files-on-a