-1

I have the variable:

set "whattodelete=*xxx* *yyy* *zzz*"

and the following directory tree:

C:\Temp
  Folder1    Folder2    Folder3
    1aaa1      2aaa2      ...
    1bbb1      2bbb2
    1ccc1      2ccc2
    1xxx1      2xxx2
    1yyy1      2yyy2
    1zzz1      2zzz2

where 1aaa1 might be either directory or file.

I've read this: Command line tool to delete folder with a specified name recursively in Windows?

but can't figure out how to add loop for variable which contains many files/directories. I suspect that here might be one more inner or outer loop but I'm not so close with variable expansion. Could you help me?

maaboo
  • 137
  • 2
  • 13
  • Please [edit your question](https://stackoverflow.com/posts/48408403/edit) providing us with the script you have written so far, _not somebody elses question with different files, directory structures and several different answers_! – Compo Jan 23 '18 at 18:42
  • Take the [tour], read [Ask] and provide an [MCVE]. – jwdonahue Jan 23 '18 at 20:31
  • Open a command prompt window and run `for /?` to get output the help for this command on several pages used for looping in Windows command environment. `for %%I in (%whattodelete%) do del /F /S /Q "C:\Temp\%%~I"` should work for your task. – Mofi Jan 24 '18 at 07:29

1 Answers1

1

This works for me:

@echo off
setlocal EnableDelayedExpansion EnableExtensions 
set "whattodelete=*xxx* *yyy* *zzz*"
cd C:\Temp
for /f "usebackq tokens=*" %%i in (`dir /b /s /a:d %whattodelete%`) do (
  rd /s /q "%%i"
  )
maaboo
  • 137
  • 2
  • 13