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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recursive Delete folders and files

Status
Not open for further replies.

ironbear6

Technical User
Oct 17, 2010
2
SE
i need help with a vbscript.
i'm a complete newbie.
i'm sitting on a Windows Server 2008 and i need a script that recursivly deletes folders, subfolders and files.
the folder is located in D:\Shared\temp
i just want to delete files and folders that are older than 24 hours old.
i don't want it to delete the Shared folder, only the contents of temp subfolder and its subfolders only if they are older than 24 hours.

i have come only this far:

Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("D:\Shared\temp")
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
If DateDiff("h", Now, srcFile.DateCreated) < -24 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub


I don't think that the current script deletes folder,subfolders or files unless they are 0 Bytes
if it isn't too much trouble can you eplain where the recursion starts and ends

P.s. Where can i schedule the task/script that it runs at 1:30 am?

Thanks a bunch
 
you dont have any recursion. (well unless you count the one enumeration of the files in d:\shared\temp)


I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Yeah i know that i don't have recursion, that's what i need help with, i wanted a vbscript that recursivly deletes folders subfolders and files, i need help, plz, anyone, help me to make a vbscript that does that
 
mrmovie posted a FAQ on recursion here: faq329-5515

Notice how the 'getInfo' subroutine calls itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top