Delete in ALL Dirs
Posted: 13 Jul 2012 03:40
How do I make a batch to delete all files in every possible directory (hidden included) that have this certain extension (.ext for example)?
Thanks!
Thanks!
Code: Select all
@echo off &setlocal enableDelayedExpansion
for /r %%? in (
"*.ext"
) do (
echo(
echo.attrib -r -a -s -h "%%~?" &&echo.del /f /q "%%~?" ||echo.[error:!errorLevel!] attrib -r -a -s -h '%%~?'
)
pause
exit
Code: Select all
attrib -r -a -s -h /S "*.ext"
del /f /s /q "*.ext"
drgt wrote:What about delete all files that DO NOT match a list of extensions?
Code: Select all
for /f "delims=" %%a in ('dir /b /s /a') do (
if /i "%%~xa" NEQ ".ext" del /a /q /f "%%a"
)
Code: Select all
@echo off
::set your extensions.
::xtension examples: ext, xtn
set "extensions=.ext .xtn"
for /f "delims=" %%a in ('dir /b /s /a') do (
set "xdel="
for %%e in (%extensions%) do (
if /i "%%~xa" == "%%e" set "xdel=0"
)
if not defined xdel del /a /q /f "%%a"
)