# Is there a batch file command to remove all folders/files within the parent folder?



## 1cainr (Jul 27, 2011)

Hello,

I would like to try and remove all the files and folders within a certain directory - e.g. c:\Test

Ive tried using: RMDIR /Q /S "C:\Test" however this removes everything including the folder 'Test' which i woudl like to keep.

The folder name within the 'Test' folder will be different everytime, is there a command which enables a batch file to delete all within the 'Test' folder?

Thanks,

Richard


----------



## Squashman (Apr 4, 2003)

Move to the Parent Directory first by either using the Change Directory command or the PUSHD command.


----------



## 1cainr (Jul 27, 2011)

Hi Squashman,

Thank you for responding to my post.

Could you give an example?

Thanks,


----------



## Squashman (Apr 4, 2003)

Here is a better solution for you.


```
for /D %%I in ("C:\temp\*") do rmdir /s/q "%%I"
del /q C:\temp\*
```


----------



## 1cainr (Jul 27, 2011)

Hi Squashman,

Thank you 

One last thing, could you explain whats happening. I understand del.. (Deleting the directory listed quietly); however what does the first line do?

Thanks,


----------



## Squashman (Apr 4, 2003)

First line is removing the directories within the TEMP folder.


----------

