A directory is a container that is used to contain subdirectories and files. When working with filesystem, might be need to remove all files and subdirectories contained in a directory. It can be called recursive deletion. This tutorial explains how to remove directory recursively on Windows.
Create few directories and files for testing:
mkdir docs\dir_1 docs\dir_2 img\dir_1
echo Hello world> docs\dir_1\test.txt
echo Hello world> docs\dir_2\test.txt
Method 1 - CMD
To remove directory recursively, use rmdir
command with /s
parameter. The /q
parameter can be used to enable quiet mode. This mode does not prompt the user to confirm when deleting a directory tree.
rmdir /s /q docs
Specify paths of the directories separated by space in order to remove multiple directories recursively:
rmdir /s /q docs img
Method 2 - PowerShell
Use Remove-Item
command in PowerShell to remove directory recursively:
Remove-Item -Recurse -Force docs
To remove multiple directories recursively, specify paths of the directories separated by comma as follows:
Remove-Item -Recurse -Force docs, img
Leave a Comment
Cancel reply