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!
Delete in ALL Dirs
Moderator: DosItHelp
Re: Delete in ALL Dirs
The DEL command can help you there.
Type this for help:
DEL /?
Type this for help:
DEL /?
Re: Delete in ALL Dirs
'
or
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"
Delete in ALL Dirs
Thanks.
What about delete all files that DO NOT match a list of extensions?
What about delete all files that DO NOT match a list of extensions?
Re: Delete in ALL Dirs
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"
)
Edit
Sorry, I misread your last line. You want a list of extensions.
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"
)