Bulk Delete Folder method rollup by using batch _dos/bat

Source: Internet
Author: User
Tags goto

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.