Reputation: 23
I found this post in regards to wildcards in directories. However, my problem is that I have multiple varying directory names between my static directories. For example:
O:\123456 Client Name\Spring\Shoot 1 12345\01 MHP 01\PlCache\GreenScreen\
O:\121212 Someone Else\Spring\Shoot 1 21212\01 MHP 02\PlCache\GreenScreen\
The above link only allows for one wildcard directory instead of muliples.
Within these GreenScreen folders, I have .png files I wish to delete. How would I write a .bat file that deletes *.png within O:\ *\GreenScreen\ ?
Upvotes: 2
Views: 3059
Reputation: 41287
Here's a simpler option - it also echos the del commands to the screen until you remove the echo
keyword.
@echo off
for /d /r "o:\" %%a in (GreenScreen*) do if /i "%%~nxa"=="GreenScreen" echo del "%%a\*.png"
Upvotes: 0
Reputation: 80203
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:"
FOR /f "tokens=1*delims=" %%a IN (
'dir /s /b /a-d "%sourcedir%\*.png" '
) DO (
SET "targetpath=%%~pa"
IF "!targetpath:~-13!"=="\GreenScreen\" ECHO DEL "%%a"
)
GOTO :EOF
The required DEL commands are merely ECHO
ed for testing purposes. After you've verified that the commands are correct, change ECHO DEL
to DEL
to actually delete the files.
I've changed to starting directory to U:
to suit my system.
Upvotes: 2