3

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\ ?

2 Answers 2

2
@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 ECHOed 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.

Sign up to request clarification or add additional context in comments.

1 Comment

This works perfectly! Thank you! I couldn't figure it out myself to save my life
0

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" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.