I want to write a batch file to delete all audio/video files under multiple folders (folder names are 0-99999, not consecutive, some may be missing). Please, experts, help answer this. Thanks.
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
@echo off
for /f %%i in ('dir /ad /b') do (
echo %%i| findstr "^*$">nul && echo %%i
)
pause
Originally posted by namejm at 2006-9-28 04:45:
Try the code below, it might be useful (the code is for demonstration purposes; if you think it's reliable, just change the later echo %%i to del /q %%i):
@echo off
for /f %%i in ('dir /ad /b') do (
...
Originally posted by tide2046 at 2006-9-28 05:34:
Someone gave me a code snippet yesterday, pretty similar to this one
But there's a bit of a problem
This will delete audio/video files in all number-named folders under a certain drive letter
Now my boss's instruction is: ...
@echo off
setlocal enabledelayedexpansion
for /f %%i in ('dir /ad /b /s') do (
set route=%%i
set route_=!route:%cd%=!
set route_=!route_:\=!
echo !route_!|findstr "^*$">nul && (
for %%j in (avi wmv mpg mpeg rm rmvb mov divx mp3 wav wma swf) do (
if exist %%i\*.%%j del /a /f %%i\*.%%j
)
)
)
pause
at 2006-9-28 05:34:
This will delete audio/video files in all number-named folders under a certain drive letter
Now my boss's instruction is: only audio/video files in folders whose parent directory is numeric, and whose subdirectory name is also numeric, may be deleted
That is: for example D:/music/123/*.rm files like this cannot be deleted
But: D:3213/321/*.rm files like this need to be deleted
@echo off
::__Quickly delete specified files in all subdirectories named with pure numbers under the current directory.
::__Before testing, please remove the line del /a /q "!route!\*.%%c" 1>nul 2>nul first; if it works, then execute the deletion!
set root=%cd%
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir /ad /b /s') do (
set route=%%i
set route_=!route!:
set "route_=!route_:%root%=!"
set "route_=!route_:\=!"
call :go
)
echo Code execution finished^^!
pause
:go
set num=!route_:~0,1!
if not "!num!"==":" (
set term=
for %%a in (0 1 2 3 4 5 6 7 8 9) do (
if "!num!"=="%%a" (
set route_=!route_:~1!
set term=
goto go
)
)
if "!term!"=="" goto :eof
goto go
)
::__For more audio/video types, add them below in the FOR statement in the current format.
for %%c in (avi mp3 rm rmvb mp4 wmv wav swf) do (
if exist "!route!\*.%%c" (
echo Folder to operate on__!route!
del /a /q "!route!\*.%%c" 1>nul 2>nul
)
)
goto :eof