How to Delete Files and Folders Using Command Prompt on Windows 10

How to Delete Files and Folders Using Command Prompt on Windows 10

To delete files and folders using Command Prompt on Windows 10, you can use the following commands:

To delete a file:

Code snippet
del filename

For example, to delete the file “myfile.txt”, you would use the following command:

Code snippet
del myfile.txt

To delete a folder:

Code snippet
rmdir foldername

For example, to delete the folder “myfolder”, you would use the following command:

Code snippet
rmdir myfolder

To delete a folder and all of its contents:

Code snippet
rd /s foldername

For example, to delete the folder “myfolder” and all of its contents, you would use the following command:

Code snippet
rd /s myfolder

Note: When you delete a file or folder using Command Prompt, it is permanently deleted and cannot be recovered. Be sure to double-check the name of the file or folder before you delete it.

Here are some additional tips for deleting files and folders using Command Prompt:

  • You can use the wildcard character (*) to delete multiple files or folders at once. For example, to delete all files with the .txt extension, you would use the following command:
Code snippet
del *.txt
  • You can use the /s switch to delete a folder and all of its subfolders. For example, to delete the folder “myfolder” and all of its subfolders, you would use the following command:
Code snippet
rd /s myfolder
  • You can use the /q switch to suppress the confirmation prompt when deleting a file or folder. For example, to delete the file “myfile.txt” without being prompted, you would use the following command:
Code snippet
del /q myfile.txt
Al Mahbub Khan
Written by Al Mahbub Khan Full-Stack Developer & Adobe Certified Magento Developer

Full-stack developer at Scylla Technologies (USA), working remotely from Bangladesh. Adobe Certified Magento Developer.