Introduction
Sometimes, we need to delete temporary files or old log files or text files using some service of Windows Task Scheduler. Today, I am going to discuss how to create Task Scheduler in Windows and archive old log files.
Background
In your computer, Winrar software should be installed. We only need to create a batch file and execute some command in the batch file.
Using the Code
Set Windows Environmental variable to point to installed Winrar application
- Right click on My Computer
to open popup
- Click Properties to open
the dialog box
- Click on Advance system
settings to open System properties dialog box
Now open Notepad and add the following contents in that
WinRAR a -r YOURTARGETZIPFILENAME
SOURCEFILETOZIP (This is for zipping)
Eg. WinRAR
a -r C:\Test.zip C:\Test.txt
cd DIRNAME (directory from
where you will delete log files)
del /Q /F /S YOURFILENAME
Now, save the file as “Test.bat”
Now let's configure Windows Task Scheduler.
Configure
Task Scheduler
- Click Start menu
- Find Task Scheduler, click
to open to Task Scheduler Window
- Click Create Basic Task to
open a dialog box
- Type
TestScheduler
in text
box. Click Next button
- Select “Daily” radio
button
- Click Next
- Set Start time of the task
to start
- Click Next
- Select “Start a program”
radio button
- Click Next
- Click Browse and select Test.bat
- Click Next, Click Finish
Now you are ready to go. Happy coding!!!