auto delete files by file extension location and date range script

Im pretty new to window scripting, but im a decent VB coder. Im trying to create a .vbs script that i can link to task manager and run periodically. (once a week maybe) I need a script that can automatically delete log files from a specific directory on my server, with a specific file type and have it delete files that are older then 3 weeks or 21 days. The automatic deletion part of this project can be accomplished by using the script and linking to task manager.

Attached ive included a snippet of code ive found that is supposed to be able to do this. Being new to scripting i havent been able to figure out where to mod this code to make it do what i need. This snippet doesnt actually delete the files, its supposed to just show me the file names in an 'OkOnly' box. I dont want to actually have it delete the files prior to knowing it runs correctly.  

1.) The parts i cant figure out so far, is how do i single out the directory i want to script to analyze.
2.) The part about the date range is static, i need dynamic. This snippet has a variable for date (strDate) and the formula is CreationDate < strDate.  I need something more like, Creation date < date-21 (current date, i think the syntax is 'date').

Thanks in advance.
strDate = "20031102000000.000000+000"
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * From CIM_DataFile Where CreationDate < '" & strDate & "'" & _
        " AND Extension = 'doc'")
For Each objFile in colFiles
    Wscript.Echo objFile.Name

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You might be better off using this article as a starting point:

Replace "C:\Scripts" with the desired directory and set the date range in the dtmDate variable.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.