Announcement

Collapse
No announcement yet.

Deleting Folders older than a certain date

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

  • Deleting Folders older than a certain date

    Greetings,
    We have an FTP server that our customers will be uploading files to for our support organization to troubleshoot with. Since i do not want to rely on the support team to remember to delete folders every 90 days, I need a script that deletes folders with a create date that is 90 days or older unless it has the phrase NODELETE in the folder name. I have one that will delete files older than a certain date that works great, but it doesn't work for folders.

    If it will help, i can attach the vbs script for deleting files if you think that will help

    any help would be greatly appreciated.

    thanks

    aaron

  • #2
    Re: Deleting Folders older than a certain date

    Post the script you use now so we can just "fix" it, or do you want us create a new one?

    Most times it is easier just to modify what you have as everyone codes different and you would have to figure out how to get my code to work in your program.

    Hobie

    Comment


    • #3
      Re: Deleting Folders older than a certain date

      Here is the current script that we use to delete files:

      Code:
      Option Explicit
      
      Dim RetentionPeriod, _
          SystemDate, SystemYear, JulianDay, SystemDateStamp, _
          ObjFileSystem, ObjFolder, ObjFileCollection, oExec, objFile, WshShell, _
          FileYear, FileJulianDay, FileDateStamp, _
          Command, DateDifference
      
      'Find Today's Date Information.
      RetentionPeriod = 90
      SystemDate = Date
      SystemYear = Year(SystemDate)
      JulianDay = SystemDate - DateValue("1/1/" & SystemYear) + 1
      If (JulianDay < 10) Then
        JulianDay = "00" & JulianDay
      ElseIf (JulianDay < 100) Then
        JulianDay = "0" & JulianDay
      Else
        JulianDay = JulianDay
      End If
      SystemDateStamp = SystemYear & JulianDay
       
      'Clean up old log files.
      Set objFileSystem = CreateObject("Scripting.FileSystemObject")
      Set objFolder = objFileSystem.GetFolder("C:\Program Files\EVault InfoStage Services\AMP Proxy Service\Logs")
      Set objFileCollection = objFolder.Files
      For Each objFile in ObjFileCollection
        FileYear = Year(objFile.DateCreated)
        FileJulianDay = objFile.DateCreated - DateValue("1/1/" & FileYear) + 1
        If (FileJulianDay < 10) Then
          FileJulianDay = "00" & FileJulianDay
        ElseIf (FileJulianDay < 100) Then
          FileJulianDay = "0" & FileJulianDay
        Else
          FileJulianDay = FileJulianDay
        End If
        FileDateStamp = Int(FileYear & FileJulianDay)
        DateDifference = SystemDateStamp - FileDateStamp
        If (DateDifference > 365) Then
          DateDifference = DateDifference - 365
        End If
        If DateDifference > RetentionPeriod Then
          objFile.Delete()
        End If
      Next
       
      'End of script.
      Let me know if there is anything you can do to help

      thanks

      app

      Comment


      • #4
        Re: Deleting Folders older than a certain date

        What about powershell?

        Something like this (untested)

        Code:
         
        #Sets variable Date to current date
        $Date=get-date
        
        #Sets Date variable back 90 days
        $Date=$Date.AddDays(-90)
        
        #Lists all files in the folder that were last written to over 90 days ago
        Get-ChildItem 'C:\FTPfolder' -recurse | where-object {$_.LastWriteTime -lt $date -and $_.name -notlike '*NODELETE*'} | remove-item -recurse -force
        Source modified a bit from here:
        http://arstechnica.com/phpbb/viewtop...?f=17&t=169895

        I can't test from my Mac
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Deleting Folders older than a certain date

          Originally posted by Dumber View Post
          I can't test from my Mac
          Is that so? I haven't tried it either yet as there is no Fink package yet available. After one is released, I sure will install it to my brand new iMac.

          You should include a test for not trying to delete directores. Like so,

          if($_IsPsContainer -and ...){...}

          -vP

          Comment


          • #6
            Re: Deleting Folders older than a certain date

            Oh that is really cool!! Is everything ported correctly?
            Is there also an iPad version available
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment

            Working...
            X