Loading ...
Sorry, an error occurred while loading the content.
 

Re: [BATCH WORLD] Delete files older than 7 days (or more)

Expand Messages
  • Daniel Lim
    Michael, How do i change your script to delete folder that s dated older that 7 days? instead of files? BY the way, I m using xp pro and the log file part
    Message 1 of 8 , Aug 6, 2003
      Michael,
      How do i change your script to delete folder that's dated older that 7 days?
      instead of files?
      BY the way, I'm using xp pro and the log file part doesn't work, NO log
      files being created after deleting the files

      newbie, thank

      >From: Michael Marquart <micm@...>
      >Reply-To: batchworld@yahoogroups.com
      >To: batchworld@yahoogroups.com
      >Subject: [BATCH WORLD] Delete files older than 7 days (or more)
      >Date: Wed, 6 Aug 2003 20:58:27 +1000
      >
      >
      >It seems that people often ask for a batch file that will delete files
      >older than a certain amount of time.
      >So since this task is a FAQ I thought it would be useful to have a common
      >solution for all microsoft operating systems, and so I cobbled together
      >such a beast.
      >
      >It's only been alpha tested under Windows 98SE but I see no reason why it
      >shouldn't work under all systems. Enjoy.
      >
      >
      >@echo off
      >if not "%3"=="" goto start
      >echo.Purpose: to delete specified files n days or older
      >echo. in the folder specified on the command line.
      >echo. (if -s is used it will include all subdirectories as well)
      >echo.
      >echo. NOTE 1: Currently it only prints the del command to the screen so
      >echo. remove the word ECHO after p2= to activate it, after testing.
      >echo.
      >echo. Syntax: %0 "Drv:\Folder Name" filespec.ext number_of_days [-s]
      >echo.
      >echo.Example: %0 "C:\Program Files\Data" *.zip 8 -s
      >echo.
      >echo. will delete *.zip files 8 days and older
      >echo. from the "C:\Program Files\Data" folder
      >echo. and recurse through the DATA Folders subdirectories too.
      >echo.
      >echo. NOTE 2: The "Drive:\Folder Name" is enclosed in DOUBLE QUOTES ("")
      >echo. The filespec.ext should only contain alphanumeric characters
      >echo.
      >echo. Compatible with Win9x/ME/NT/W2K/XP
      >echo.
      >echo. Forfiles can be found at
      >echo. ftp://ftp.microsoft.com/ResKit/y2kfix/x86/forfiles.exe
      >goto end
      >:start
      >set p1=%comspec% /C
      >set p2=ECHO del 0x22@PATH\@FILE0x22
      >FORFILES -p%1 -m"%2" -d-%3 %4 -c"%p1% if not @ISDIR==TRUE %p2%"
      >::
      >:: the following 2 lines can be used to write a log file (remove ":: ")
      >:: if exist c:\log.txt del c:\log.txt
      >:: FORFILES -p%1 -m"%2" -d-%3 %4 -c"%p1% if not @ISDIR==TRUE
      >%p2%>>c:\log.txt"
      >::
      >for %%a in (p1 p2) do set %%a=
      >:end
      >
      >
      >
      >--
      >Regards,
      >Michael

      _________________________________________________________________
      The new MSN 8: advanced junk mail protection and 2 months FREE*
      http://join.msn.com/?page=features/junkmail
    • Michael Marquart
      ... Thanks for the feedback, I fixed the logfile and made it a permanent feature. It s not tested, so be very careful when there are mass deletions involved.
      Message 2 of 8 , Aug 6, 2003
        On Wed, 06 Aug 2003 16:57:15 +0000, Daniel Lim wrote:

        > Michael,
        > How do i change your script to delete folder that's dated older that 7 days?
        > instead of files?
        > BY the way, I'm using xp pro and the log file part doesn't work, NO log
        > files being created after deleting the files
        >
        > newbie, thank

        Thanks for the feedback, I fixed the logfile and made it a permanent
        feature.

        It's not tested, so be very careful when there are mass deletions involved.
        Remove the ECHO after p2= only when you are sure the log file shows it is
        working correctly.

        Please let me know how it goes.


        @echo off
        if not "%3"=="" goto start
        echo.Purpose: to delete specified folders that are n days or older
        echo. in the folder specified on the command line.
        echo. (if -s is used it will include all subdirectories as well)
        echo.
        echo. NOTE 1: Currently it only prints the del command to the screen so
        echo. remove the word ECHO after p2= to activate it, after testing.
        echo.
        echo. Syntax: %0 "Drv:\Folder Name" "folderspec[.ext]" number_of_days [-s]
        echo.
        echo.Example: %0 "C:\Program Files\Data" *.* 8 -s
        echo.
        echo. will delete all folders (with or without extensions) 8 days
        echo. and older from the "C:\Program Files\Data" folder
        echo. and recurse through the DATA Folders subdirectories too.
        echo.
        echo. NOTE 2: The "Drive:\Folder Name" and "folderspec[.ext]"
        echo. should be enclosed in DOUBLE QUOTES ("")
        echo.
        echo. Compatible with W2K/XP
        echo.
        echo. Forfiles can be found at
        echo. ftp://ftp.microsoft.com/ResKit/y2kfix/x86/forfiles.exe
        goto end
        :start
        set p1=%comspec% /C
        set p2=ECHO del /f /q 0x22@PATH\@FILE0x22
        ::
        :: the following 3 lines will write a log file (remove if not needed)
        echo Writing log file, please wait...
        if exist c:\log.txt del c:\log.txt
        FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"
        ::
        echo Deleting, please wait...
        FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE %p2%"
        echo Done!
        for %%a in (p1 p2) do set %%a=
        :end




        --
        Regards,
        Michael
      • Daniel Lim
        Micheal, Can t get it to work, It delete only files but not the folder. The log file works fine, it s possible to append the log instead of overwrite? and
        Message 3 of 8 , Aug 7, 2003
          Micheal,
          Can't get it to work, It delete only files but not the folder.

          The log file works fine, it's possible to append the log instead of
          overwrite? and seperate them with
          ---------------------------------------------------
          Date mmddyyy

          Thank you


          >From: Michael Marquart <micm@...>
          >Reply-To: batchworld@yahoogroups.com
          >To: batchworld@yahoogroups.com
          >Subject: Re: [BATCH WORLD] Delete files older than 7 days (or more)
          >Date: Thu, 7 Aug 2003 15:12:02 +1000
          >
          >On Wed, 06 Aug 2003 16:57:15 +0000, Daniel Lim wrote:
          >
          > > Michael,
          > > How do i change your script to delete folder that's dated older that 7
          >days?
          > > instead of files?
          > > BY the way, I'm using xp pro and the log file part doesn't work, NO log
          > > files being created after deleting the files
          > >
          > > newbie, thank
          >
          >Thanks for the feedback, I fixed the logfile and made it a permanent
          >feature.
          >
          >It's not tested, so be very careful when there are mass deletions involved.
          >Remove the ECHO after p2= only when you are sure the log file shows it is
          >working correctly.
          >
          >Please let me know how it goes.
          >
          >
          >@echo off
          >if not "%3"=="" goto start
          >echo.Purpose: to delete specified folders that are n days or older
          >echo. in the folder specified on the command line.
          >echo. (if -s is used it will include all subdirectories as well)
          >echo.
          >echo. NOTE 1: Currently it only prints the del command to the screen so
          >echo. remove the word ECHO after p2= to activate it, after testing.
          >echo.
          >echo. Syntax: %0 "Drv:\Folder Name" "folderspec[.ext]" number_of_days [-s]
          >echo.
          >echo.Example: %0 "C:\Program Files\Data" *.* 8 -s
          >echo.
          >echo. will delete all folders (with or without extensions) 8 days
          >echo. and older from the "C:\Program Files\Data" folder
          >echo. and recurse through the DATA Folders subdirectories too.
          >echo.
          >echo. NOTE 2: The "Drive:\Folder Name" and "folderspec[.ext]"
          >echo. should be enclosed in DOUBLE QUOTES ("")
          >echo.
          >echo. Compatible with W2K/XP
          >echo.
          >echo. Forfiles can be found at
          >echo. ftp://ftp.microsoft.com/ResKit/y2kfix/x86/forfiles.exe
          >goto end
          >:start
          >set p1=%comspec% /C
          >set p2=ECHO del /f /q 0x22@PATH\@FILE0x22
          >::
          >:: the following 3 lines will write a log file (remove if not needed)
          >echo Writing log file, please wait...
          >if exist c:\log.txt del c:\log.txt
          >FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"
          >::
          >echo Deleting, please wait...
          >FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE %p2%"
          >echo Done!
          >for %%a in (p1 p2) do set %%a=
          >:end
          >
          >
          >
          >
          >--
          >Regards,
          >Michael

          _________________________________________________________________
          Tired of spam? Get advanced junk mail protection with MSN 8.
          http://join.msn.com/?page=features/junkmail
        • Michael Marquart
          replace del /f /q with rd /s /q That ll nuke those sob s ;) and for the log, replace this ... echo Writing log file, please wait... if exist c: log.txt del
          Message 4 of 8 , Aug 7, 2003
            replace "del /f /q" with "rd /s /q"

            That'll nuke those sob's ;)


            and for the log, replace this

            :: the following 3 lines will write a log file (remove if not needed)
            echo Writing log file, please wait...
            if exist c:\log.txt del c:\log.txt
            FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"

            with this

            :: the following 3 lines will write a log file (remove if not needed)
            echo Writing log file, please wait...
            echo ========================================================>>c:\log.txt
            echo %date% at %time% >>c:\log.txt
            echo ========================================================>>c:\log.txt
            FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"


            Good Luck.


            --
            Regards,
            Michael
          • Michael Marquart
            Did you get this to work, Daniel? ... -- Regards, Michael
            Message 5 of 8 , Aug 11, 2003
              Did you get this to work, Daniel?


              On Fri, 8 Aug 2003 14:13:23 +1000, Michael Marquart wrote:

              > replace "del /f /q" with "rd /s /q"
              >
              > That'll nuke those sob's ;)
              >
              >
              > and for the log, replace this


              --
              Regards,
              Michael
            • Daniel Lim
              the delete parts is working!! thanks, what you meant to replace on the log files? Thanks ... _________________________________________________________________
              Message 6 of 8 , Aug 11, 2003
                the delete parts is working!! thanks, what you meant to replace on the log
                files?
                Thanks


                >From: Michael Marquart <micm@...>
                >Reply-To: batchworld@yahoogroups.com
                >To: batchworld@yahoogroups.com
                >Subject: Re: [BATCH WORLD] Delete files older than 7 days (or more)
                >Date: Mon, 11 Aug 2003 21:27:17 +1000
                >
                >
                >Did you get this to work, Daniel?
                >
                >
                >On Fri, 8 Aug 2003 14:13:23 +1000, Michael Marquart wrote:
                >
                > > replace "del /f /q" with "rd /s /q"
                > >
                > > That'll nuke those sob's ;)
                > >
                > >
                > > and for the log, replace this
                >
                >
                >--
                >Regards,
                >Michael

                _________________________________________________________________
                The new MSN 8: smart spam protection and 2 months FREE*
                http://join.msn.com/?page=features/junkmail
              • Michael Marquart
                ... No worries. and for the log, replace these 4 lines ... echo Writing log file, please wait... if exist c: log.txt del c: log.txt FORFILES -p%1 -m%2 -d-%3 %4
                Message 7 of 8 , Aug 11, 2003
                  On Mon, 11 Aug 2003 14:07:29 +0000, Daniel Lim wrote:

                  > the delete parts is working!! thanks, what you meant to replace on the log
                  > files?
                  > Thanks

                  No worries.

                  and for the log, replace these 4 lines

                  :: the following 3 lines will write a log file (remove if not needed)
                  echo Writing log file, please wait...
                  if exist c:\log.txt del c:\log.txt
                  FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"

                  with this

                  :: the following 5 lines will write a log file (remove if not needed)
                  echo Writing log file, please wait...
                  echo ========================================================>>c:\log.txt
                  echo %date% at %time% >>c:\log.txt
                  echo ========================================================>>c:\log.txt
                  FORFILES -p%1 -m%2 -d-%3 %4 -c"%p1% if @ISDIR==TRUE echo %p2%>>c:\log.txt"




                  --
                  Regards,
                  Michael
                Your message has been successfully submitted and would be delivered to recipients shortly.