0

I have a folder structure:

C:\foo1\foo2\foo3\foo4\foo5

I want delete that folder completely by:

C:\>rmdir /S foo1

Respectively rmdir /s foo1, rmdir /S /Q foo1, rmdir /s/q foo1, rd /s/q foo1, rd /s/q "C:\foo1" do the same.

But, not the wohle folder foo1 is deleted. Only foo5 is deleted, with the result message:

foo1\foo2\foo3\foo4 - The directory is not empty.

I repeat the command rmdir /S foo1. Now foo4 is deleted. I have to repeat this step 5 times until foo1 is completely deleted.

But the description of param /S is:

Deletes a directory tree (the specified directory and all its subdirectories, including all files).

What is the reason that only the last directory is deleted but not the entire directory structure?

Using cmd as administrator does not change the result.

5
  • Not reproducible on Windows 10 1909 : rmdir /s /q foo1 deletes foo1 and all its contents.
    – harrymc
    Commented Mar 7, 2020 at 9:49
  • I use currently Windows 1709 (Build 16299.1087)
    – gotwo
    Commented Mar 7, 2020 at 10:05
  • Why not update to 1909?
    – harrymc
    Commented Mar 7, 2020 at 10:07
  • before rmdir /S foo1 del /s /q foo1\*.*
    – somebadhat
    Commented Mar 7, 2020 at 12:51
  • Thank you for the proposal. But C:\>del /s /q foo1\*.* has no effect.
    – gotwo
    Commented Mar 7, 2020 at 15:13

1 Answer 1

0

The reason of the problem was Windows Explorer, which looks into C:\foo1\foo2\foo3\foo4\foo5. And the same in C:\foo1\foo2\foo3\foo4 and so on. Surprisingly, the deletion is forced when the rmdir command is called multiple times.

The effect was for me additionally reproducable and not reproducable. Interestingly one PC with Windows version 1903 had this effect, another also with version 1903 hadn't this effect.

I want delete the directories via batch file reliably. The method which I use now:

for /l %%i in (1, 1, 5) do (if exist foo1 (rd /s/q foo1))

Respectively on command-line with %i instead of %%i:

for /l %i in (1, 1, 5) do (if exist foo1 (rd /s/q foo1))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .