0

I want to delete the maps Hoi and Hoi2 from \TestMap\Customer(x), however I do not want to delete Hoi1 and Hoi2 from TestMap\Ei.

File structure:

C:\TestMap\Customer1\Ei

  • C:\TestMap\Customer1\Ei\Hoi
  • C:\TestMap\Customer1\Ei\Hoi2

C:\TestMap\Customer1\Ham

C:\TestMap\Customer1\Hoi

C:\TestMap\Customer1\Hoi2

C:\TestMap\Customer1\Kaas

C:\TestMap\Customer1\Vis

Let's pretent that TestMap has another 100 folders from Customer1 to Customer 100 with all these same subfolders. So basically the script needs to run for every folder in TestMap.

I have found a code on StackOverflow, however this will delete ALL of the folders with a specific name, including subfolders.(Batch command to delete all subfolders with a specific name)

Anyone that might know to solution? Thanks in advance.

Steven
  • 5
  • 2

1 Answers1

0

You could just loop with for /d check if exist and delete:

@echo off
for /d %%i in ("%userprofile%\Desktop\TestMap\*") do (
   if exist "%%~i\hoi\" rd /s /q "%%~i\hoi"
   if exist "%%~i\hoi2\" rd /s /q "%%~i\hoi2"
)
pause
Gerhard
  • 22,678
  • 7
  • 27
  • 43