MicrosoftWindowsWindows 10

Some folders and files are impossible to delete using Windows Explorer.

Regardless of the reason, these can only be force deleted using command line only.

This article explains using cmd to delete folder or file successfully.

Deleting Files and Folders using Command Line in Windows

The most important thing to remember here is the syntax of the path and file/folder name.

When typing file name, notice whether there is a gap (space) in it.

For example, if the folder name has no space in it, it can be written as-is.

CLI naming syntax

This is called a recursive action.

Furthermore, you must also know how to change your working directory when inside a Command Line Interface.

Use the commandcdto change your directory, followed by the correct syntax.

cd back

This is especially helpful so that you jot down in the correct spelling of the target file or folder.

To view the contents of the current working directory in Command Prompt and PowerShell, throw in inDir.

By default, there are 2 command-line interfaces built intoWindows 10 Command Prompt and Windows PowerShell.

cd forward

Both of these are going to be used to delete content from a computer.

Del/Erase command in cmd

DelandErasecommands in Command Prompt are aliases of one another.

Meaning, both perform the same function regardless of which one you use.

change WD

These can be used to remove individual items (files) in the current working directory.

Remember that it cannot be used to delete the directories (folders) themselves.

ReplaceFile/FolderNamewith the name of the item you wish to remove.

change drive

However, the subdirectories within the folder will not be changed at all.

This problem can be resolved by using the /s switch.

The slash followed by s signifies the recursive option.

dir

with each confirmation, 2 text files were removed, as we had stated earlier in this example.

Here is how:

The/qillustrates that the action be takenquietly.

These commands are used to remove the entire directory and subdirectories (recursively) including their contents.

del erase cmd

Of course, this can also be performed with the/qoption so that you are not prompted with a confirmation.

Now lets see how you’re able to remove multiple selective files or folders.

If it will not, the action would not be taken.

confirmation yes no

The overall functionality and logic are the same.

We recommend that youlaunch Windows PowerShell with administrative privilegesbefore proceeding.

The good thing is that you do not need to specify recursive action.

recursive del

Here is an example:

The command shown above will remove all.txt files in the directory New folder.

This will also make the destination folder empty, hence making it removable.

You will now see that the folder that was previously unremovable is now empty.

quiet del

you might proceed to delete it using any of the methods discussed in this article.

Closing words

The command line is a blessing for Windows users.

you might use any of these commands to remove even the most stubborn files and folders on your setup.

rmdir cmd

3

Get weekly insights, tips and exclusive content delivered straight to your inbox.

Talk to us straight and get your questions answered right away

directory is not empty

rmdir recursive

rmdir recursive quiet

del multiple files

rd multiple folders

before vs after

del asterisk

different directory rmdir

cmd if

PS all

PS delete selective 1

PS asterisk

PS different location

robocopy

Download Windows 11 IoT Enterprise LTSC ISO

Startup folder in all versions of Windows

Download Windows 11 Version 24H2

source: www.itechtics.com