How to delete files and folders recursively with cmd?

How to delete files recursively with the cmd command prompt in Windows?

Tutorial on how to delete files recursively with cmd, i.e. from a folder and all its subfolders. Use the del batch command line and the recursive option. The Windows delete command provides this useful option automate the deletion process. For example, if you have a huge amount to delete but need to keep the folder and subfolder’s structure.

Advantages of recursivity using Windows cmd

Indeed, it’s the main goal of this tutorial, to be effective and avoid browsing all the subfolders in order to search for a specific file name or extension. The main option that I suggest using is the deletion confirmation, this way you can control one last time which files are recursively deleted. Please note that the files deleted in recursive mode with the command line are not stored in the Windows Recycle Bin. Here is below a list of a few advantages it offers:

  1. Efficiency: It allows for quick deletion of multiple files and directories with a single command, eliminating the need to select each file or folder individually.
  2. Precision: With the use of wildcards and specific file extensions, users can target they want to remove, ensuring that only the intended items are deleted without affecting others.
  3. Depth: It can effortlessly reach and remove files nested deep within multiple subdirectories, which might be tedious through a graphical interface.
  4. Scripting and Automation: For repetitive tasks, users can create batch scripts to delete specific sets of files, allowing for easy automation and scheduling of clean-up tasks.
  5. Resource Light: Using cmd is less resource-intensive than graphical interfaces, ensuring smoother system performance, especially when dealing with a large number of files.
  6. Flexibility: Advanced users can combine file deletion with other command-line operations, achieving complex file management tasks seamlessly.

Make sure you delete the proper files only. The operation is irreversible.

Batch delete files in subdirectories in command prompt

To delete files recursively using the explicit path, without any confirmation prompt, use this command:

del /s "C:\Folder\"

You can also use this variation, without the quotes and without any confirmation prompt. The quotes are mandatory when the complete path of the folder, or the file, contains spaces.

del /s C:\Folder\

Recursively suppress files with a confirmation

This option is the one I recommend. Indeed, make sure to double check and confirm before all files are deleted. Please note that this option deletes only the text files as we use the *.txt filter.

del /p /s SubFolder_1\*.txt
Delete files recursively with cmd with a prompt confirmation in Windows 10
Delete files recursively with cmd using a prompt confirmation

Then a prompt is displayed for the files that match, in alphabetical order:
c:\Folder\SubFolder_1\file (1).txt, Delete (Y/N)?

Delete files and directories without confirmation

To force the deletion with no prompt at all use the delete quiet mode. Useful with a lot of files.

del /q /s SubFolder_2\*.txt
Delete files recursively with cmd, i.e., from folder and subfolders in quiet mode without confirmation
Delete files recursively with cmd in quiet mode without confirmation

Conclusion and safety tips for batch recursive deletion

To conclude, the del /s recursive option is the fastest and easiest way to delete files recursively with cmd in Windows. Using cmd for recursive file deletion is powerful, but it requires caution. Always double-check paths and file filters to target the correct items. Since files deleted via cmd bypass the Windows Recycle Bin, ensure you have backups of essential data.

When in doubt, use the confirmation prompt (/p option) to verify each file’s deletion. Always prioritize data security when harnessing the command line’s efficiency. Here is how to copy recursively files and folders using the xcopy command.