# Batch RD Command



## bradjoe96 (Dec 19, 2011)

I'm working a small, personal program made in batch to remove the contents of my Downloads folder. I recently found out that wildcards do not work with RD command so I can't tell the program to remove all of the directories, just the files and the files in the subdirectories. I need a command to delete all of the subdirectories out of the Downloads folder, but still leaving the Downloads folder on there.

Thanks in advance,



Brad


----------



## Squashman (Apr 4, 2003)

Use a for loop to list all the directories and then use the RD command to delete them.


----------



## bradjoe96 (Dec 19, 2011)

I'm not sure how you would use a for loop to do this. Example? I can post my current code if needed.


----------



## Frank4d (Sep 10, 2006)

If I understand correctly that you want a completely empty Downloads folder, this should work:

rd /s /q c:\Downloads
md c:\Downloads


----------



## Squashman (Apr 4, 2003)

Always Always Always post the code you are currently using when asking for help.


----------



## Squashman (Apr 4, 2003)

Frank4d said:


> If I understand correctly that you want a completely empty Downloads folder, this should work:
> 
> rd /s /q c:\Downloads
> md c:\Downloads


That will work for sure but I know sometimes people don't like doing it that way. So here is what I was thinking with the for loop.

```
pushd c:\users\USERNAME\downloads
REM removing files from the main downloads directory
del /q *
REM removing directories, sub directories and all files
for /d %%I in (*) do rd /s /q "%%~I"
```


----------

