# Solved: batch to delete everything except



## matrixebiz (Nov 13, 2010)

Hello, can someone help me to create a batch file that will remove everything in a directory and subdirectories except jpg, bmp and png while still maintaining the full directory/subdirectory structure


is there a Windows program that will do this already? Thx


----------



## matrixebiz (Nov 13, 2010)

Found something. Thx anyway

```
REM Use at your own risk, it does a mass DELETE of everything!
SET /p ExcludeFiles=What file type should be kept (NOT deleted)? Type the file name(s) inside parantheses. example: (pdf) or (shp dbf shx)     
SET /p MapDrive=What drive letter is the folder in? example: c or n     
SET /p Directory=Drag the folder you would like to modify into this command prompt then press ENTER.     
%MapDrive%:
cd %Directory%
attrib +a *.* /s
echo %date%
for %%i in %ExcludeFiles% do attrib -a *.%%i /s
echo %date%
del %Directory%\*.* /s /a:a /q
echo %date%
attrib +a %Directory%\*.* /s
echo %date%
```


----------

