VBScript File Directory operations RRS feed

  • Question

  • I have the following codes that will delete files that are 2 days old; keeping 2 days worth of files on the directory.

    For Each objFile in objFiles 
       If objFile.DateLastModified < (Date() - 2) Then
          objFile.Delete (True)
       End If

    The problem with that is, it's calculating weekends. No files will be created on weekends. So, on Monday, when the script runs, it'll delete everything older than Sunday; leaving only Monday's data. I would like to keep previous Friday and Monday - only deleting everything older than previous Friday.

    I'm not sure how (or if possible) to incorporate the built-in function Weekday to my script.

    Tuesday, February 18, 2014 7:41 PM