How to specify multiple wildcards in a folder directory in CMD

北城余情 提交于 2019-12-24 12:40:25

问题


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


回答1:


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




回答2:


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"


来源:https://stackoverflow.com/questions/22838599/how-to-specify-multiple-wildcards-in-a-folder-directory-in-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!