Script to delete files

Hey experts,

  I need a windows shell script to make a loop on files in a folder (around 1/2 a million files); and delete files that have their date created older than a certain date (1/1/2006 for example)

I mainly need help on the for & if syntax and on the checking for the date; many thanks in advance
LVL 3
mte01Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
johnny_the_knifeConnect With a Mentor Commented:
Give this a crack.

Obviusly, you should test it before you use it!

Just set the deletionDate variable and adjust the folder as required.
'
' Script to delete all files in a folder beyond a certain date
'
Dim deletionDate
Dim fso
Dim oFile
Dim oFolder
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("c:\temp")
 
deletionDate = "2007-06-10" 'yyyy-mm-dd
 
 
For Each oFile in oFolder.Files
    If DateDiff("d", oFile.DateCreated, deletionDate) > 0 Then
        ' File exceeds the date selected, delete it
        fso.DeleteFile oFile, True ' Delete it even if it is read only!
    End If
Next
 
Set oFolder = Nothing
Set oFile = Nothing
Set fso = Nothing

Open in new window

0
 
mte01Author Commented:
>>johnny_the_knife

Thanks a lot! I'll be trying it now..
0
All Courses

From novice to tech pro — start learning today.