Announcement

Collapse
No announcement yet.

Object not a collection error

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Object not a collection error

    Does anyone know why I am getting an "Object not a collection" error on line 58, char 3 with this script? Usually you get that error if you have a misspelling, but the only word I have on that line is "next"

    Code:
    ' folder to start search in...
    path = "C:\mmurray\*.log"
     
    ' delete files older than 7 days...
    killdate = date() - 11
     
    arFiles = Array()
    set fso = createobject("scripting.filesystemobject")
     
    ' Don't do the delete while you still are looping through a
    ' file collection returned from the File System Object (FSO).
    ' The collection may get mixed up.
    ' Create an array of the file objects to avoid this.
    '
    SelectFiles path, killdate, arFiles, true
     
    nDeleted = 0
    for n = 0 to ubound(arFiles)
      '=================================================
      ' Files deleted via FSO methods do *NOT* go to the recycle bin!!!
      '=================================================
      on error resume next 'in case of 'in use' files...
      arFiles(n).delete true
      if err.number <> 0 then
        wscript.echo "Unable to delete: " & arFiles(n).path
      else
        nDeleted = nDeleted + 1
      end if
      on error goto 0
    next
     
    WScript.Echo nDeleted & " of " & ubound(arFiles)+1 _
      & " eligible files were deleted"
     
    
    sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
      on error resume next
      'select files to delete and add to array...
      '
      set folder = fso.getfolder(sPath)
      set files = folder.files
     
      for each file in files
        ' uses error trapping around access to the
        ' Date property just to be safe
        '
        dtlastmodified = null
        on error resume Next
        dtlastmodified = file.datelastmodified
        on error goto 0
        if not isnull(dtlastmodified) Then
          if dtlastmodified < vKillDate then
            count = ubound(arFilesToKill) + 1
            redim preserve arFilesToKill(count)
            set arFilesToKill(count) = file
          end if
        end if
      next
     
      if bIncludeSubFolders then
        for each fldr in folder.subfolders
          SelectFiles fldr.path,vKillDate,arFilesToKill,true
        next
      end if
    end sub

  • #2
    Re: Object not a collection error

    Comment out the On Error... lines, then you see what realy causes this termination of the script.

    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Object not a collection error

      oK did that, and the error was at line 40, char 3, "path not found." So I guess it is not liking my "C:\mmurray\*.log", which is really the *.log

      Am I putting the path in the right way so it only deletes the .log files?

      Comment


      • #4
        Re: Object not a collection error

        path = "C:\mmurray"
        strFileType ="log"
        <...>
        For each file in files
        If fso.GetExtensionName(file.name) = strFileType Then
        <...>
        <...>
        End If
        Next
        <...>


        \Rems
        Last edited by Rems; 15th November 2007, 01:05. Reason: typo

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Object not a collection error

          Thanks Rems!

          Comment

          Working...
          X