Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use script I found in Windows

Status
Not open for further replies.

tyant

Programmer
Jun 1, 2001
68
0
0
AU
I'm not a programmer .... Technical User. I found the below script to delete files after 30 days. Does this sit in side a .VBS file or something. I hope the script will delete a folder and all its contents based on modified date

NumberOfDaysOld = 30
strPath = "C:\Test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files

For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next

For Each objSubfolder in colSubfolders
Set colFiles = objSubfolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next

Next
 
Save it as a .vbs file then double click it.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for your help

Should this work? I trying to get it to delete all folder in directory so number of days = 0
If I get that working I will change number of days


Dim NumberOfDaysold, objFSO, StrPath, objFolder

NumberOfDaysOld = 0
strPath = "C:\Temp"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)

If objFolder.DateLastModified < (Date() - NumberOfDaysold) Then
objFolder.Delete
End If
 
You will probably get more answers in the correct forum - in this case forum329

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top