batch-filesymantec

Delete SEP VirusDef by date


I have SEP (Symantec Endpoint Protection) in my network. i want to delete old virus definition folders that take allot of size.

this is the "VirusDef" Folder content:

Directory of \\10.1.66.101\c\Program Files\Common Files\Symantec Shared\VirusDefs

04/06/2014  09:14 PM    <DIR>          .
04/06/2014  09:14 PM    <DIR>          ..
03/24/2014  06:19 AM    <DIR>          20140322.002
03/26/2014  08:37 PM    <DIR>          20140325.009
03/31/2014  01:05 AM    <DIR>          20140329.002
04/03/2014  10:24 AM    <DIR>          20140401.023
09/15/2010  02:43 PM    <DIR>          BinHub
10/24/2013  12:56 AM           500,892 Cat.DB
04/03/2014  10:24 AM                34 definfo.dat
09/15/2010  02:43 PM    <DIR>          TextHub
01/10/2013  11:37 PM           500,660 umcat_01.db
04/03/2014  01:42 PM               141 usage.dat
               4 File(s)      1,001,727 bytes
               8 Dir(s)   1,114,185,728 bytes free

I have to remain the last modified folder with number, for this case it's 20140401.023 and the other files and folders.

I want to delete the old folders with the numbers such as:

20140322.002
20140325.009
20140329.002

ofcource, those folders get their name by the date the were created.

please help :)


Solution

  • @echo off
      setlocal enableextensions disabledelayedexpansion
      set "where=\\10.1.66.101\c\Program Files\Common Files\Symantec Shared\VirusDefs"
      for /f "skip=1 delims=" %%a in (
        'dir /b /ad /tc /o-d "%where%" ^|findstr /r /c:"^[0-9]*\.[0-9]*$"'
      ) do echo rmdir /s /q "%where%\%%a"
    

    This uses dir command to enumerate the directories, sorted by creation date descending, filtered by findstr to only return the directories with numbered names and extension, from this list, skip the first one (the newer) and delete the rest of the list.

    rmdir is only echoed to console. If the output is right, remove the echo command.