Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways to batch delete folders as required using batch processing

Shulou Source: shulou.com Published: 2022-06-03 09:30:04 09月21日 Update

This article mainly explains "what are the methods of deleting folders in batches according to requirements using batch processing". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn together "what are the methods of deleting folders in batches according to requirements using batch processing"!

Example 1:

There are a bunch of folder structures like this, for example

abcde

|-----abcd2000

|---------0003

|----------0004

........

|------abcd2001

|---------0006

|----------0002

........

|------abcd2002

|---------0005

|----------0002

........

cdefe

|-----cdefe2000

|---------0003

|----------0004

........

|------cdefe2001

|---------0006

|----------0002

........

|------cdefe2002

|---------0005

|----------0002

........

Now I want to delete the second level directory according to the year, for example, only delete the directory containing 2000 and 2001 fields such as abcd2000,abcd2001, cdefe 2000,cdefe2001 and its lower level directory. What should I do?

@echo offsetlocal enabledelayedexpansion:: set primary folder set folder=D:\abcdefor /f "delims=" %%a in ('dir/ad /b %folder %') do ( set str=%%a if "! str:~-4! "=="2000" rd %folder%\! str! /s /q if "! str:~-4! "=="2001" rd %folder%\! str! /s /q)

Example 2:

All my pictures are saved in F:\Photography, and there are N folders below, all of which have a file called ".picasaoriginals". There is a dot before this name!!!

For example, F:\Photography\I @\I @ Qingdao\.picasaoriginals

Now we need a batch process to delete all F:\Photography subfolders that contain.picasaoriginals.

And, just to be safe... Please prompt the program if you want to delete this information...

@echo offecho Scanning files... for /f "delims=" %%a in ('dir /a-d /s /b .picasaoriginals') do (if /i "%%~nxa"==".picasaoriginals" (if exist "%%~a" (echo del /f /q "%%~a">DelNow.bat))if exist "DelNow.bat" (ping 0 -n "2">nulcall:qd)del /f /q DelNow.batexit :qdclsset /p q= Confirm deletion? (Enter Y OK, others exit): clsif /i "%q%"=="Y" (echo is deleting... ping 0 -n "2">nulcall DelNow.batclsecho Delete complete! ping 0 -n "2">nul)goto :eof

Example 3:

Delete all files and folders with qqq in batch

@echo offecho.... File search, please wait... c:\for /r c: %%a in (.) do @if exist %%a\qqq.* del %%a\qqq.* for /r c: %%a in (.) do @if exist %%a\qqq rd /s /q %%a\qqqd:\for /r d: %%a in (.) do @if exist %%a\qqq.* del %%a\qqq.* for /r d: %%a in (.) do @if exist %%a\qqq rd /s /q %%a\qqqe:\for /r e: %%a in (.) do @if exist %%a\qqq.* del %%a\qqq.* for /r e: %%a in (.) do @if exist %%a\qqq rd /s /q %%a\qqqf:\for /r f: %%a in (.) do @if exist %%a\qqq.* del %%a\qqq.* for /r f: %%a in (.) do @if exist %%a\qqq rd /s /q %%a\qqqgoto end:endecho good bye! Thank you for reading, the above is "what are the methods of using batch processing to delete folders in batches as required", after learning this article, I believe everyone has a deeper understanding of what methods are used to delete folders in batches as required, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Files folders methods directories examples learning content current two-tier information names pictures piles fields that is age ideas situations articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno Shulou Tech Info MySQL Huawei