You can use the following syntax in Command Prompt (CMD) to delete a directory:
rmdir directory_name
This particular example will delete the specified directory in the current directory.
Note: Ensure that the directory you want to delete is empty, otherwise you will receive an error. If you want to delete a directory and all its contents, use the /S
flag.
The following example shows how to use this syntax in practice.
Example: Deleting a Directory in CMD
Suppose that we want to delete a directory named my_app in the following path:
C:\Users\admin\Documents\cmd_script
We can type the following command to delete the directory:
rmdir C:\Users\admin\Documents\cmd_script\my_app
The following screenshot shows how to use this syntax in practice:
We can see that the directory my_app has been deleted from C:\Users\admin\Documents\cmd_script.
Suppose we want to delete a directory and all its contents, you can use the /S
flag:
rmdir /S C:\Users\admin\Documents\cmd_script\my_app
The following screenshot shows how to use this syntax in practice:
C:\>rmdir /S C:\Users\admin\Documents\cmd_script\my_app
C:\Users\admin\Documents\cmd_script\my_app, Are you sure (Y/N)? y
C:\>cd C:\Users\admin\Documents\cmd_script\
C:\Users\admin\Documents\cmd_script>dir
Volume in drive C is OSDisk
Volume Serial Number is 8854-7D9F
Directory of C:\Users\admin\Documents\cmd_script
10/06/2024 10:41 AM <DIR> .
10/06/2024 10:41 AM <DIR> ..
10/06/2024 10:27 AM <DIR> my_demoApp
0 File(s) 0 bytes
3 Dir(s) 612 909 244 416 bytes free
C:\Users\admin\Documents\cmd_script>
We can see that the directory my_app and all its contents have been deleted from C:\Users\admin\Documents\cmd_script.
Conclusion
We can use the rmdir command in cmd to delete all the contents from the specified directory.
Note: Be cautious when using the /S
flag as it will delete all files and subdirectories within the specified directory.
You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.