1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Rep Power

    Any Batch file Programmers here?!

    I know this might sound easy but I've made an ussessful attempt to script in dos batch file something very simple. The idea is I have some directories (lets say four of them) and I want to delete 3 bogus ones, I already know the good one and have stored its name in a variable %DIREC%. for example
    Directory of C:\dev

    04/12/2006 04:18 PM <DIR> .
    04/12/2006 04:18 PM <DIR> ..
    04/12/2006 04:18 PM <DIR> good
    04/12/2006 04:18 PM <DIR> random11
    04/12/2006 04:18 PM <DIR> random2
    04/12/2006 04:18 PM <DIR> random3
    0 File(s) 0 bytes
    6 Dir(s) 18,289,057,792 bytes free

    the good corresponds to %DIREC%.
    Any ideas? Thanks
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    This might need a few tweaks
    for /d %i in (*) do (
      if not "%i" == "%DIREC%" del /s %i
    The first part gets a list of all the directory names in the current dir.
    The second part deletes those dirs which do not match.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo