Announcement

Collapse
No announcement yet.

Batch file to remove directories older than x

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

  • Batch file to remove directories older than x

    Does anyone have a good script out there to remove directories older than x.

    I am trying to use unixutils find command but I cannot get it to work

    Code:
    find "\var\log\syslog\archive"  -type d -mtime +2 -exec rm -rf {} \;
    Can anyone suggest another way to remove directories older than x, or tell me whats wrong with that find command?

  • #2
    Re: Batch file to remove directories older than x

    Look just a few threads down this forum and there are at least two very similar ones -- one is at http://forums.petri.com/showthread.php?t=58391
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Batch file to remove directories older than x

      You could use forfiles.exe, what operating system is on the computer?

      Code:
      @echo off
      
      Set "Target=D:\archive"
      
      Set "daysold=365"
      
      If Exist "%Target%" (
      "forfiles.exe" /p "%Target%" /d -%daysold% /c "cmd.exe /c IF @isdir==TRUE RD @Path /S /Q"
      )
      /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


      • #4
        Re: Batch file to remove directories older than x

        You could use Robocopy with the /MINAGE:n also.
        Caesar's cipher - 3

        ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

        SFX JNRS FC U6 MNGR

        Comment

        Working...
        X