How to delete files recursively with the cmd command prompt in Windows?
How to delete files with cmd, 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.
Table of Contents
How to delete files recursively with 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.
Make sure you delete the proper files only. The operation is irreversible.
Delete files from folders and subfolders using del
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\
Suppress all 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
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 folders 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
To conclude, the del /s recursive option is the fastest and easiest way to delete files recursively with cmd in Windows. Here is how to copy recursively files and folders using the xcopy command.