Example one:
Have such a large pile of folder structures, such as
Abcde
|-----abcd2000
|---------0003
|----------0004
........
|------abcd2001
|---------0006
|----------0002
........
|------abcd2002
|---------0005
|----------0002
........
Cdefe
|-----cdefe2000
|---------0003
|----------0004
........
|------cdefe2001
|---------0006
|----------0002
........
|------cdefe2002
|---------0005
|----------0002
........
Now want to delete the second level of the directory, such as only delete abcd2000,abcd2001,cdefe2000,cdefe2001 such as the 2000,2001 field directory and its lower directory, what to do?
@echo off
setlocal enabledelayedexpansion
:: Set one level folder
set FOLDER=D:\ABCDE
for/f "delims="%%a in (' dir/ ad/b%folder% ') do (
set str=%%a
if "!str:~-4!" = = "R" Rd%folder%\!str! /s/q
If "!str:~-4!" = = "2001" Rd%folder%\!str! /s/q
)
Example two:
All my pictures are saved in F:\Photography, and there are more than N folders, all of which have a file called ". Picasaoriginals" ... Notice that the name has a dot before it!!!
For example F:\Photography\ i @\ my @ Qingdao \.picasaoriginals
Now we need to use a batch to delete all F:\Photography subfolders containing the. Picasaoriginals This folder ...
Also, for the sake of insurance ... Please indicate in your program whether you want to delete this information ...
@echo off
echo is scanning files ...
for/f "delims="%%a in (' dir/a-d/s/b. picasaoriginals ') do (
if/i "%%~nxa" = ". Picasaoriginals" (
if Exis T "%%~a" (
echo del/f/q "%%~a" >>delnow.bat))
if Exist "Delnow.bat" (
ping 0-n "2" ; nul
call:qd
)
del/f/q delnow.bat
exit
: QD
cls
set/p q= confirm deletion? (Enter y OK, other exits):
cls
if/i "%q%" = = "Y" (
echo is being deleted ...)
Ping 0-n "2" >nul call
delnow.bat
CLS
echo deletion complete!
Ping 0-n "2" >nul
)
Goto:eof
Example three:
Bulk delete all files and folders with QQQ on your computer
@echo off
echo .... File lookup, please wait ...
C:\
for/r C:%%a in (.) does @if exist%%a\qqq.* del%%a\qqq.*
for/r C:%%a in (.) do @if exist%%A\QQQ rd/s/q% %A\QQQ
d:\
for/r D:%%a in (.) Doing @if exist%%a\qqq.* del%%a\qqq.* for/r
D:%%a in (.) Doing @if exist%%A\QQQ RD/S/q%%a\qqq
e:\
for/r e:%%a in (.) Doing @if exist%%a\qqq.* del%%a\qqq.*
for/r e:%%a in (.) Doing @if E Xist%%A\QQQ rd/s/q%%a\qqq
f:\ for/r
F:%%a in (.) Do @if exist%%a\qqq.* del%%a\qqq.*
for/r f:%%a I N (.) do @if exist%%A\QQQ rd/s/q%%a\qqq
goto end
: End
echo Good bye!