Shoutbox

File delete - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: File delete (/showthread.php?tid=61882)

File delete by t1a0s on 06-28-2006 at 12:01 PM

I found this VBScript code on the internet that allows me to delete files in a folder when I run it:

code:
Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case.
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("d", Now, srcFile.DateCreated) < -20 Then
fso.DeleteFile srcFile, True
End If
Next
Wscript.Echo "Files Deleted successful"
End Sub
I've used it and it works, but how can I change it so it deletes everything (files and folders) in the specified folder, and not just the files?