Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 09-08-2007 7:28pm
    #1
    Closed Accounts Posts: 6,131 ✭✭✭


    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,131 ✭✭✭subway


    cheers!

    thansk for doing that :)


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


    You're welcome


Advertisement