Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

help to create a scheduled task to delete all files greater than 25 days in a folder

  • 09-08-2007 07:28PM
    #1
    Closed Accounts Posts: 6,113 ✭✭✭


    trying to manage window using automated tasks as much as i can.
    i have a folder thats constantly filling with files (tv recorder)
    can anyone suggest a (free) tool that will automatically purge files once they reach 25 days old (thats when the folder usually fills)
    or can this be done using scheduled tasks?

    os is xp


Comments

  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    You can use a vbs script to delete the files. Then just use the Scheduled Tasks in windows to set the script to run once a day.
    dtmDate = Date - 25
    
    strDay = Day(dtmDate)
    
    If Len(strDay) < 2 Then
        strDay = "0" & strDay
    End If
    
    strMonth = Month(dtmDate)
    
    If Len(strMonth) < 2 Then
        strMonth = "0" & strMonth
    End If
    
    strYear = Year(dtmDate)
    
    strTargetDate = strYear & strMonth & strDay
    
    strComputer = "."
    
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    
    Set FileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='C:\Scripts'} Where " _
            & "ResultClass = CIM_DataFile")
    
    For Each objFile In FileList
        strDate = Left(objFile.CreationDate, 8)
        If strDate < strTargetDate Then
                objFile.Delete
        End If
    Next
    

    Just save that code to a file named deleteFiles.vbs. Remember to change c:\scripts to the folder name where the files you want to delete reside. Then config the scheduled task. Easy as that. And free!!!


  • Closed Accounts Posts: 6,113 ✭✭✭subway


    cheers!

    thansk for doing that :)


  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    You're welcome


Advertisement