# VBS Script to Delete Folder's Contents...



## jwinathome (Mar 9, 2007)

I apologize for posting this in the wrong section before!

Problem: User's temp folders that store recently opened PDF files gets full and has to be manually emptied so they can continue to open PDFs. Is there a script I can create to do this automatically? Maybe something the user can run on their PC when it happens?

Thanks for your suggestions.


----------



## jwinathome (Mar 9, 2007)

Never mind, I got it. In case anyone is interested:


dim aweekago
dim dir

dir = "C:\Documents and Settings\jwingate\Local Settings\Temp"
aweekago = date -1

Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(dir)
For Each file In fldr.Files
If file.datecreated < aweekago then file.delete
Next


----------



## tsiris (Jul 27, 2004)

The script you gave deletes only files in this directory. How can we make it to delete folders as well?


----------



## jwinathome (Mar 9, 2007)

I think that is a bit more tricky, and Everything has to be cleared in the folder before the actual folder can be deleted, or something like that. I saw the script for it, but its crazy complex for a person that doesn't know scripting (like me!)

I really only needed the script to empty this temp folder for my users.


----------

