Windows was born to help users to use computers through a graphical interface. In an age where everything was controlled from commands and systems such as DOS (or MS-DOS), Windows came with a much more intuitive graphical interface designed to take advantage of using a new peripheral: the mouse. Today we all use Windows with the mouse, and we navigate through our files and folders using File Explorer. However, it is also possible to do it classically using CMD.
Although when we talk about the terminal, we generally associate it with Linux, Windows also has its own “terminal” inherited from MS-DOS, the well-known ” Command Prompt, “Command Prompt ” or simply CMD.
Users who want to use the old-fashioned operating system can use the command prompt to run specific commands on the system and perform basic tasks. If we have ever used this console, the first commands we will have used will be ping to see if we have Internet connectivity, cd to navigate through the directories on our hard drive, and dir to show a list of all the files and folders in said directory.
If we want to learn a little more about CMD commands, today we will show you how to delete files and folders from CMD.
Delete files and folders from CMD
Although it is always easier and faster to select the files in the explorer and press the delete key to delete them, we can also do it from CMD.
To do this, we have to use the DEL command. This command (DELete) will allow us to delete files from our hard drive quickly. To do this, using the CD command, we will move to the directory that contains the file that we are going to delete and execute the following command:
DEL / F / A <file.extension>
The / F parameter will allow us to force the file’s deletion, while the / A will enable us to delete only the files marked “ready for archiving” by Windows.
If we want to delete a folder, the process is similar, but instead of using the DEL command to delete it, we will have to use RD (Remove Directory).
To do this, we will place ourselves with the CD command in the folder that contains the folder that we want to delete, and we will execute the following command:
RD / S <folder>
The / S parameter indicates that we will also delete all the subfolders within the folder. If we do not put it and there is a folder inside, it will not delete the main folder.
Byenow, a program to delete many folders at once
Deleting folders one by one from CMD is fast if we have few to delete. But when the number of folders increases, things get complicated. And it can turn into a nightmare.
byenow is a free program that runs from the CMD itself, but it will help us delete many files, and folders in one go very quickly to no longer have to depend on the rmdir command.
This program’s syntax is straightforward, so if we place the executable inside the Windows PATH, we can always have it handy for when we need it. It will be enough to execute the command «byenow» in a CMD window, followed by the directory that we want to delete and the parameter we want to execute. We can choose from a total of 7 parameters:
- -p: preview all content without removing anything.
- -s: first shows us a list with the content, and then deletes it.
- -1: shows the program execution progress in one line.
- -e: List all errors.
- -y: does not ask for confirmation to delete.
- -tn: uses n number of threads on our processor to erase data much faster.
- -n – Use Windows 10’s NtDeleteFile API to delete files.
What if it won’t let me delete the files from CMD?
Maybe when trying to execute the DEL or RD parameter, the command prompt will return an error message. This is usually due to a permission issue. For example, if we are trying to delete a file from the system, or a folder that we do not own, CMD will not let us.
To fix it, open CMD with Administrator permissions, and that’s it. Except for protected system files, with CMD as Administrator, you can delete any files.