Windows cmd remove directory with files

In Windows, a folder can be deleted from command line(CMD) using rmdir command. Find syntax and examples for rmdir command to force delete folder contents and recursively delete subfolders.

Do you want to delete a directory from Windows command prompt(CMD)? This post explains how to use the command rmdir to delete folders and their contents. You can also find examples for each use case of folder deletion – empty folders, non empty folders, folders with white spaced names etc.

Delete folder from CMD

Run the command rmdir on the folder.

rmdir directoryname

Example:

C:>rmdir emptydir
C:>

How to delete a non empty folder

The simple rmdir does not work for folders having some content.

C:>rmdir nonemptydir
The directory is not empty.

Use /s option to delete the folder contents along with the folder. This deletes all subfolders recursively.

C:>rmdir /S nonemptydir
nonemptydir, Are you sure (Y/N)? y 
C:>

Force delete a folder without confirmation

To  force delete directory, without being asked for confirmation, we can use /Q switch.

rmdir /Q /S nonemptydir

We can also use ‘rd’ in place of ‘rmdir‘. Both names refer to the same command. This command works on Windows 2000, Windows XP, Server 2003, Vista, Windows 7 and 10.

Deleting directory with white spaces in the name

Rmdir can delete files with whitespaces in the name, you just need to wrap up the folder name in double quotes as shown in the below example.

rmdir /Q /S "folder with spaces in the name"

Delete contents of a directory but keep the directory

The usecase here is to delete all the contents of the directory but keep the parent directory so that we do not need to create it again. rmdir /Q /S does not work here as it deletes the parent directory too. Rather the below commands should do the trick.

forfiles /P directory_path /M * /C "cmd /c if @isdir==FALSE del @file"
forfiles /P directory_path /M * /C "cmd /c if @isdir==TRUE rmdir /S /Q @file"

This works in 2 steps – the first command deletes all files, whereas the second one deletes all subdirectories.

Errors

To delete a directory, you should have appropriate access permissions on the directory. Otherwise rmdir throws ‘Access denied’ error.

The Windows Command Processor cmd.exe has two internal commands for deletion of files and folders:

  1. The command DEL is for the deletion of files with usage help output on running in a Windows command prompt window either help del or del /?.
  2. The command RMDIR or with shorter name RD is for removal of directories with usage help output on running in a Windows command prompt window either help rmdir or rmdir /? or help rd or rd /?.

Deletion of all *.svn files in an entire folder tree

There can be used in a Windows command prompt window or a Windows batch file the following command to delete really all files of which long or short 8.3 file name is matched by the wildcard pattern *.svn in the directory %USERPROFILE%Projects or any of its subdirectories:

del /A /F /Q /S "%USERPROFILE%Projects*.svn" >nul 2>&1

The usage of option /A to match all files independent on the file attributes replaces the implicit default /A-H to ignore hidden files. So even files with hidden attribute are deleted by this command because of using the option /A. Files matched by wildcard pattern *.svn with hidden attribute set are ignored on not using the option /A.

The option /F forces a deletion of files with file extension .svn which have the read-only attribute set. There would be output the error message Access is denied. if a *.svn file has the read-only attribute set and the option /F is not used on running the command DEL.

The quiet option /Q prevents the user confirmation prompt Are you sure (Y/N)?.

The option /S results in searching not only in the specified directory, but also in all its subdirectories including those with hidden attribute set even on not using option /A for files of which long or short 8.3 name is matched by the wildcard pattern *.svn.

The two redirections >nul and 2>&1 result in redirecting the list of deleted files output to handle STDOUT (standard output) and the error messages output to handle STDERR (standard error) to the device NUL to suppress every output.

There are deleted also hard links and symbolic links matched by the wildcard pattern *.svn on using this command, but not the files linked to on having a file name not ending with .svn or being in a different directory tree.

Files matched by the wildcard pattern *.svn currently opened by a process (program/application) with using shared access permissions to deny all other processes to delete the file as long as being opened by this process are not deleted by this command. File system permissions can result also in files not being deleted by this command.

Deletion of all *.svn folders in an entire folder tree

There can be used in a Windows command prompt window the following command to remove really all folders matching in long or short 8.3 folder name the wildcard pattern *.svn in the directory %USERPROFILE%Projects and all its subdirectories:

for /F "delims=" %I in ('dir "%USERPROFILE%Projects*.svn" /AD /B /S 2^>nul') do @rd /Q /S "%I" 2>nul

The same command line for usage in a batch file containing @echo off at top is:

for /F "delims=" %%I in ('dir "%USERPROFILE%Projects*.svn" /AD /B /S 2^>nul') do rd /Q /S "%%I" 2>nul

There is executed on more cmd.exe in background with option /c and the command line specified between ' as additional arguments to run in background the Windows Command Processor internal command DIR to search

  • in the specified directory %USERPROFILE%Projects
  • and in all its subdirectories because of option /S
  • for just directories because of using the option /AD which includes also junctions and symbolic directory links
  • matching the wildcard pattern *.svn.

The file system entries (= directory names) matched by these criteria are output in bare format because of option /B with full path because of option /S to handle STDOUT of the background command process without surrounding " even on full directory name containing a space or one of these characters &()[]{}^=;!'+,`~. The error message output by DIR on not finding any name matching these criteria is redirected to device NUL to suppress it.

The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when the Windows Command Processor parses this command line before executing the command FOR which executes the embedded dir command line with using a separate command process started in background.

The output list of directory names with their full paths to handle STDOUT is captured by cmd.exe processing the batch file and processed by FOR after started cmd.exe closed itself.

The FOR /F option delims= defines an empty list of string delimiters which results in each entire directory name is assigned completely one after the other to the specified loop variable I.

The command RD is executed to delete quietly because of option /Q the directory with all files and all subdirectories because of option /S.

There are deleted also junctions (soft links) and symbolic directory links matched by the wildcard pattern *.svn on using this command, but not the directories linked to on having a directory name not ending with .svn or being in a different directory tree.

A directory matched by the wildcard pattern *.svn in which a file is currently opened by a process (program/application) with using shared access permissions to deny all other processes to delete the file as long as being opened by this process is not deleted by this command and of course also no directory above the directory containing the file which cannot be deleted at the moment. File system permissions can result also in directories not being deleted by this command. Windows prevents by default also the deletion of a directory which is the current working directory of any running process.

Other useful information regarding to deletion of files and folders

The directory path %USERPROFILE%Projects can be removed completely or replaced by . in the commands above to delete the files and folders matching the wildcard pattern *.svn in the current directory of the Windows Command Processor process which executes the commands.

The directory path %USERPROFILE%Projects can be replaced by %~dp0 to delete the files and folders matching the wildcard pattern *.svn in the directory of the batch file on using the command lines above in a batch file independent on which directory is the current directory on execution of the batch file.

The directory path %USERPROFILE%Projects can be replaced also by a relative path. Please read the Microsoft documentation about Naming Files, Paths, and Namespaces for more details about relative paths.

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • del /?
  • dir /?
  • for /?
  • rd /?

Run mklink /? for help on how to create file and directory links explained very well by MKLink.

See also:

  • Microsoft documentation for the Windows commands
  • SS64.com — A-Z index of Windows CMD commands

cmd Delete Folder – How to Remove Files and Folders in Windows

Sometimes it’s just faster to do things with the command line.

In this quick tutorial we’ll go over how to open Command Prompt, some basic commands and flags, and how to delete files and folders in Command Prompt.

If you’re already familiar with basic DOS commands, feel free to skip ahead.

How to open Command Prompt

To open Command Prompt, press the Windows key, and type in «cmd».

Then, click on «Run as Administrator»:

Screenshot showing how to open Command Prompt as an administrator

After that, you’ll see a Command Prompt window with administrative privileges:

command-prompt-new-window

Screenshot of Command Prompt window

If you can’t open Command Prompt as an administrator, no worries. You can open a normal Command Prompt window by clicking «Open» instead of «Run as Administrator».

The only difference is that you may not be able to delete some protected files, which shouldn’t be a problem in most cases.

How to delete files with the del command

Now that Command Prompt is open, use cd to change directories to where your files are.

I’ve prepared a directory on the desktop called Test Folder. You can use the command tree /f to see a, well, tree, of all the nested files and folders:

Screenshot after running tree /f in target directory

To delete a file, use the following command: del "<filename>".

For example, to delete Test file.txt, just run del "Test File.txt".

There may be a prompt asking if you want to delete the file. If so, type «y» and hit enter.

Note: Any files deleted with the del command cannot be recovered. Be very careful where and how you use this command.

After that, you can run tree /f to confirm that your file was deleted:

Screenshot after deleting file with del command

Also, bonus tip – Command Prompt has basic autocompletion. So you could just type in del test, press the tab key, and Command Prompt will change it to del "Test File.txt".

How to force delete files with the del command

Sometimes files are marked as read only, and you’ll see the following error when you try to use the del command:

Screenshot of error after trying to delete a read only file

To get around this, use the /f flag to force delete the file. For example, del /f "Read Only Test File.txt":

Screenshot after deleting file with the force flag

How to delete folders with the rmdir command

To delete directories/folders, you’ll need to use the rmdir or rd command. Both commands work the same way, but let’s stick with rmdir since it’s a bit more expressive.

Also, I’ll use the terms directory and folder interchangeably for the rest of the tutorial. «Folder» is a newer term that became popular with early desktop GUIs, but folder and directory basically mean the same thing.

To remove a directory, just use the command rmdir <directory name>.

Note: Any directories deleted with the rmdir command cannot be recovered. Be very careful where and how you use this command.

In this case I want to remove a directory named Subfolder, so I’ll use the command rmdir Subfolder:

Screenshot of a directory not empty error

But, if you remember earlier, Subfolder has a file in it named Nested Test File.

You could cd into the Subfolder directory and remove the file, then come back with cd .. and run the rmdir Subfolder command again, but that would get tedious. And just imagine if there were a bunch of other nested files and directories!

Like with the del command, there’s a helpful flag we can use to make things much faster and easier.

How to use the /s flag with rmdir

To remove a directory, including all nested files and subdirectories, just use the /s flag:

Screenshot after running rmdir with the /s flag

There will probably be a prompt asking if you want to remove that directory. If so, just type «y» and hit enter.

And that’s it! That should be everything you need to know to remove files and folders in the Windows Command Prompt.

All of these commands should work in PowerShell, which is basically Command Prompt version 2.0. Also, PowerShell has a bunch of cool aliases like ls and clear that should feel right at home if you’re familiar with the Mac/Linux command line.

Did these commands help you? Are there any other commands that you find useful? Either way, let me know over on Twitter.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Some folders and files are impossible to delete using Windows Explorer. These include files with long paths, names or reserved names like CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL etc. You will get an Access Denied error message when you try to delete these files using Windows Explorer, even if you are an administrator.

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.

Table of contents

  • Before we begin
  • How to remove files and folders using Command Prompt
    • Del/Erase command in cmd
    • Rmdir /rd command in cmd
    • Delete multiple files and folders
    • Delete files and folders in any directory
    • Check the existence of file or folder then remove using IF command
  • How to remove files and folders using Windows PowerShell
    • Delete multiple files and folders
    • Delete files and folders in any directory
  • Delete files and folders with complex and long paths using the command line
  • Closing words

Before we begin

Here are some important things for you to understand before we dig into removing files and folders using Command Prompt and Windows PowerShell. These tips will help you understand the terms and some basic rules of the commands that will be used further in the article.

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. However, if there is a gap in it, it will need to be written within parenthesis (“”). Here is an example:

CLI naming syntax

Another thing to remember is that you might see different outcomes while removing folders that are already empty, and folders that have some content in them. Having said that, you will need to use the dedicated options in the command to remove content from within a folder along with the main folder itself. 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 command cd to change your directory, followed by the correct syntax. Here are some examples:

One last thing that might come in handy is being able to view what content is available in the current working directory. This is especially helpful so that you type in the correct spelling of the target file or folder. To view the contents of the current working directory in Command Prompt and PowerShell, type in Dir.

dir

Now that we have the basic knowledge, let us show you how you can delete files and folders using the command line on a Windows PC.

By default, there are 2 command-line interfaces built into Windows 10 – Command Prompt and Windows PowerShell. Both of these are going to be used‌ ‌to‌ ‌delete‌ ‌content‌ ‌from‌ ‌a‌ ‌computer.

How to remove files and folders using Command Prompt

Let us start with the very basic commands and work our way up from there for Command Prompt. We recommend that you use Command Prompt with administrative privileges so that you do not encounter any additional prompts that you already might have.

Del/Erase command in cmd

Del and Erase commands in Command Prompt are aliases of one another. Meaning, both perform the same function regardless of which one you use. 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.

Use either of the following commands to do so:

Tip: Use the Tab button to automatically complete paths and file/folder names.

Del File/FolderName

Erase File/FolderName

Replace File/FolderName with the name of the item you wish to remove. Here is an example of us removing files from the working directory:

del erase cmd

If you try to remove items from within a folder, whether empty or not, you will be prompted for a confirmation action, such as the one below:

confirmation yes no

In such a scenario, you will need to enter Y for yes and N for no to confirm. If you select yes, the items directly within the folder will be removed, but the directory (folder) will remain. However, the subdirectories within the folder will not be changed at all.

This problem can be resolved by using the /s switch. In order to remove all of the content within the folder and its subdirectories, you will need to add the recursive option in the command (/s). The slash followed by “s” signifies the recursive option. Refer to the example below to fully understand the concept:

We will be using the Del command here to recursively remove the text files within the folder “Final folder,” which also has a subdirectory named “Subfolder.” Subfolder also has 2 sample text files that we will be recursively removing with the following command:

Del /s "Final folder"

Here is its output:

recursive del

As you can see in the image above, we had to enter “y” twice – once for each folder. with each confirmation, 2 text files were removed, as we had stated earlier in this example. However, if we use File Explorer, we can still see that both the directories – “Final folder” and “Subfolder” – are still there, but the content inside them is removed.

You can also make another tweak to the command so that it is executed silently and you will not be prompted for confirmation. Here is how:

Del /s /q "Final folder"

The /q illustrates that the action be taken quietly.

quiet del

Rmdir /rd command in cmd

Similar to Del and Erase, rmdir and rd are also aliases for one another, which means to remove directory. These commands are used to remove the entire directory and subdirectories (recursively) including their contents. Use the command below to do so:

rmdir "New Folder"

rmdir cmd

The above command will remove the “New folder” only if it is empty. If a folder has subdirectories, you might get the following prompt:

directory is not empty

In this case, we will need to apply the option for recursive deletion of items as we have done earlier with the Del command.

rmdir /s "Final folder"

rmdir recursive

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

rmdir /s /q "Final folder"

rmdir recursive quiet

Delete multiple files and folders

Up until now, we have completed the task of deleting single items per command. Now let’s see how you can remove multiple selective files or folders. Use the command below to do so:

For files:

Del "File1.txt" "File3.txt" "File5.txt"

del multiple files

For directories:

rd "Folder1" "Folder3" "Folder5"

rd multiple folders

Here is a before and after comparison of the directory where both of the above commands were executed:

before vs after

You can also use an asterisk (*) concatenated with a file type or file name to perform bulk removal of files with the Del command. However, Microsoft has removed the support for the use of asterisks with rmdir so that users do not accidentally remove entire folders.

Here is an example of us removing all .txt files from our current working directory:

Del "*.txt"

del asterisk

Delete files and folders in any directory

We are working on removing content within the current working directory. However, you can also use the commands we have discussed till now to remove files and folders from any directory within your computer.

Simply put the complete path of the item you want to delete in enclosed parenthesis, and it shall be removed, as in the example below:

different directory rmdir

Check the existence of file or folder then remove using IF command

We have already discussed that you can view the contents of the working directory by typing in Dir in Command Prompt. However, you can apply an “if” condition in Command Prompt to remove an item if it exists. If it will not, the action would not be taken. Here is how:

if exist File/FolderName (rmdir /s/q File/FolderName)

Replace File/FolderName in both places with the name of the item (and extension if applicable) to be deleted. Here is an example:
if exist Desktop (rmdir /s/q Desktop)

cmd if

How to remove files and folders using Windows PowerShell

The commands in Windows PowerShell to delete and remove content from your PC are very much similar to those of Command Prompt, with a few additional aliases. The overall functionality and logic are the same.

We recommend that you launch Windows PowerShell with administrative privileges before proceeding.

The main thing to note here is that unlike Command Prompt, all commands can be used for both purposes – removing individual files as well as complete directories. We ask you to be careful while using PowerShell to delete files and folders, as the directory itself is also removed.

The good thing is that you do not need to specify recursive action. If a directory has sub-directories, PowerShell will confirm whether you wish to continue with your deletion, which will also include all child objects (subdirectories).

Here is a list of all the commands/aliases that can be used in PowerShell to remove an item:

  • Del
  • Rm-dir
  • remove-item
  • Erase
  • Rd
  • Ri
  • Rm

We tested all of these commands in our working directory and each of them was successful in deleting the folders as well as individual items, as can be seen below:

PS all

As can be seen above, the syntax of all the aliases is the same. You can use any of the commands below to delete an item using PowerShell:

Del File/FolderName
Rm-dir File/FolderName
remove-item File/FolderName
Erase File/FolderName
Rd File/FolderName
Ri File/FolderName
Rm File/FolderName

Delete multiple files and folders

You can also delete multiple selective files and folders just as we did while using Command Prompt. The only difference is that you will need to provide the complete path of each item, even if you are in the same working directory. Use the command below to do so:

Del "DriveLetter:PathItemName", "DriveLetter:PathItemName"

Remember to append the file type if the item is not a directory (.txt, .png, etc.), as we have done in the example below:

PS delete selective 1

You can also use an asterisk (*) concatenated with a file type or file name to perform bulk removal of files with the Del command, as done in Command Prompt. Here is an example:

PS asterisk

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

Delete files and folders in any directory

You can also remove an item in a different directory, just like we did in Command Prompt. Simply enter the complete path to the item in PowerShell, as we have done below:

PS different location

Delete files and folders with complex and long paths using the command line

Sometimes you may encounter an error while trying to delete an item that may suggest that the path is too long, or the item cannot be deleted as it is buried too deep. Here is a neat trick you can apply using both Command Prompt and PowerShell to initially empty the folder, and then remove it using any of the methods above.

Use the command below to copy the contents of one folder (which is empty) into a folder that cannot be deleted. This will also make the destination folder empty, hence making it removable.

robocopy "D:EmptyFolder" D:FolderToRemove /MIR

In this scenario, the EmptyFolder is the source folder that we have deliberately kept empty to copy it to the target folder “FolderToRemove.”

robocopy

You will now see that the folder that was previously unremovable is now empty. You can 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 can use any of these commands to remove even the most stubborn files and folders on your computer.

Let us know which solution worked for you in the comments section down below.

Also see:

Subhan Zafar is an established IT professional with interests in Windows and Server infrastructure testing and research, and is currently working with Itechtics as a research consultant. He has studied Electrical Engineering and is also certified by Huawei (HCNA & HCNP Routing and Switching).

What is the windows equivalent of rm -r [directory-name]?

asked Aug 23, 2010 at 19:29

Eric Wilson's user avatar

Eric WilsonEric Wilson

7,69812 gold badges40 silver badges50 bronze badges

deltree if I remember my DOS.


It seems it’s been updated… this is what you want:

RMDIR /S

This removes the directory C:test, with prompts :

rmdir c:test /s

This does the same, without prompts :

rmdir c:test /s /q

Regarding the sudo part of your question, if you need more priviliges, you can first open a new shell as another user account using the runas command, like this:

runas /user:Administrator cmd
rmdir c:test /s /q

answered Aug 23, 2010 at 19:30

Colin Pickard's user avatar

Colin PickardColin Pickard

8,3893 gold badges30 silver badges38 bronze badges

7

If you want to delete a long and complicated folder structure from the command prompt that RmDir won’t touch and not even explorer can display, I’ve found robocopy can be very efficient at removing the structure.
In the example below we have a massive structure inside the folder administrator, the structure is so deep that nothing can remove it.
We create a new empty folder called (strangely enough!) «new folder».
We then use the robocopy command, telling it the source folder is «new folder» and the destination folder is «D:Administrator» with the /MIR parameter which means it will purge anything not in the source folder.

robocopy "D:new folder" D:Administrator /MIR

In this case the folder paths were so long they would not even fit in the command prompt window Screen Buffer, but Robocopy will traverse the structure and remove any «extra» files and folders (ie anything not in the new empty folder, which is everything).

answered Aug 9, 2012 at 23:13

Sean's user avatar

SeanSean

7815 silver badges3 bronze badges

2

You can do the following in PowerShell, if you’re on Windows Vista+ :

rm C:pathtodelete -r -f[orce]

answered Aug 22, 2015 at 16:51

Devesh Khandelwal's user avatar

2

For me, what works is

del /s dir

You can add /q to disable confirmation. I’ve never managed to get rmdir working (on XP)

answered May 17, 2014 at 7:42

Vincent Fourmond's user avatar

3

If you have a really really long path, (like I did because of java program error), even robocopy cant do it. It descended for about 30sec into my path and then hung.

My solution: if you can move the whole problem path from one folder to another then you can cut away recursivly and repeatedly some directory stairs from the top.

This Batch plays pingpong between the two directories leer and leer2 and cuts away 8 ‘libraries’
each time. If your path contains files, you have to add further commands to erase them.

recurdel.cmd
:loop
move c:leerlibrarieslibrarieslibrarieslibrarieslibrarieslibrarieslibrarieslibraries c:leer2
rd /S /Q c:leerlibraries
move c:leer2librarieslibrarieslibrarieslibrarieslibrarieslibrarieslibrarieslibraries c:leer
rd /S /Q c:leer2libraries
GOTO loop

Eric Wilson's user avatar

Eric Wilson

7,69812 gold badges40 silver badges50 bronze badges

answered Mar 5, 2014 at 8:37

Paulmann's user avatar

PaulmannPaulmann

511 silver badge1 bronze badge

1

From CMD Just run RD /s C:pathtodelete

Hit Y to the prompt

/s ensures all the sub directories are deleted as well.

Reference:

  • Run help RD from the command line

Wasif's user avatar

Wasif

7,5932 gold badges15 silver badges32 bronze badges

answered Jan 22, 2016 at 6:44

Rachit Ranjan's user avatar

1

In powershell:

Remove-Item "Path" -Force -Recurse

In short (nearly rm -rf):

rm  "PATH" -r -fo

answered Sep 25, 2020 at 2:10

Wasif's user avatar

WasifWasif

7,5932 gold badges15 silver badges32 bronze badges

This will delete «my folder» without prompt:

rd /s /q "C:Usersgourav.gAppDataRoamingmy folder"

answered Jul 4, 2018 at 7:09

GorvGoyl's user avatar

GorvGoylGorvGoyl

2281 silver badge12 bronze badges

You can delete a folder with subfolders and files using commands, but you need to know the correct tool for the job. On Windows 10, when you have to remove a file or folder with a command terminal, the first tool it comes to mind is the del command, but you will quickly find out that it won’t work to delete folders with subfolders recursively because the tool only deals with files.

The tool you need to use will depend on the command console if you want to delete folders with content inside of them. If you use Command Prompt, rmdir (remove directory) is the tool you want to use to delete folders recursively. On the other hand, if you are using PowerShell, Remove-Item is the cmdlet that will do the job.

This guide will teach you two ways to delete subfolders with Command Prompt and PowerShell on Windows 10.

  • Delete folders with subfolders from Command Prompt
  • Delete folders with subfolders from PowerShell

Delete folders with subfolders from Command Prompt

To delete a folder with subfolders with a command on Windows 10, use these steps:

  1. Open Start on Windows 10.

  2. Search for Command Prompt, right-click the top result, and select the Run as administrator option.

  3. Type the following command to delete an empty folder and press Enter:

    rmdir PATHTOFOLDER-NAME

    In the command, replace PATHTOFOLDER-NAME with the folder path and the folder name you want to delete. This example removes the “files” folder:

    rmdir C:files

    Delete empty folder

  4. Type the following command to delete the folder and subfolders with contents and press Enter:

    rmdir /s PATHTOFOLDER-NAME

    This example removes the “files” folder, subfolders, and files:

    rmdir /s C:files

    Delete folder with content

  5. Type the following command to delete a folder with content recursively without a confirmation prompt and press Enter:

    rmdir /s /q PATHTOFOLDER-NAME

    This example removes the “files” folder, subfolders, and files without prompting for confirmation:

    rmdir /s /q C:files

    Delete folder with subfolders quietly

Once you complete the steps, the command will delete the folders with subfolders and files from Windows 10.

The /s option deletes the folder and its content in the above command, but it prompts confirmation. The /q option ignores the prompt and deletes the folder recursively.

Delete folders with subfolders from PowerShell

To recursively delete an entire folder with a PowerShell command on Windows 10, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and select the Run as administrator option.

  3. Type the following command to delete an empty folder and press Enter:

    Remove-Item PATHTOFOLDER-NAME

    In the command, replace PATHTOFOLDER-NAME with the folder path and the folder name you want to delete. This example removes the “files” folder:

    Remove-Item C:files

    PowerShell delete folder command with confirmation

  4. Type the following command to delete an empty folder and press Enter:

    Remove-Item -Recurse -Force PATHTOFOLDER-NAME

    This example removes the “files” folder:

    Remove-Item -Recurse -Force C:files

    PowerShell recursively delete folder

After you complete the steps, the command will delete the folder on Windows 10 and its contents with or without a prompt, depending on the command you choose.

The -Recurse option tells the command that you want to delete the folder and its contents without prompt confirmation. The -Force option is not required but allows for erasing special items, including read-only or hidden files.

We may earn commission for purchases using our links to help keep offering the free content. Privacy policy info.

All content on this site is provided with no warranties, express or implied. Use any information at your own risk. Always backup of your device and files before making any changes. Privacy policy info.

In some cases, Windows is not allowing some users to delete their files or folders. You can use the command prompt to delete a file or a folder if you encounter such a problem. In this article, we will show you how exactly you can use this method to delete files and folders.

  • How to delete files on Windows 10 with CMD
  • How to delete folders on Windows 10 with CMD
  • Force Uninstall

Deleting files on Windows 10 with command prompt

The built-in del command can help you delete files on Windows 10. You have to point out the specific path to this file on your PC.

To use this method do the following:

  1. Open the Start Menu and in the search bar type “cmd”. Right-click on the result and select “Run as Administrator”
  2. Type in the field the following command where PATH will be replaced with the full path to the file you want to delete.
    del path
    delete file with command prompt
  3. After that press Enter

Lets’ see this example to clarify the whole process:

You want to delete a file called Info.txt that is located on your desktop. Use the following command in the Command Prompt where you replace username with your own username:

Del “C:UsersusernameDesktopInfo.txt”

After you enter this command the file will be deleted from the Desktop.

There are several commands that you can use to modify a bit the del command.

For instance, you can add the /p parameter to the command to get Command Prompt to be asked for confirmation before deleting a file.

You can also add the /f parameter to force delete a read-only file.

You can also use Revo Uninstallers’ force uninstall feature if you have trouble removing stubborn programs.

To delete folders in Windows 10 with CMD you have to use the rmdir command

This command will remove all folders including the subfolders and files in them.

To use this command do the following:

  1. Open the Start Menu and in the search bar type “cmd”. Right-click on the result and select “Run as Administrator”
  2. Type in the field the following command where PATH will be replaced with the full path to the file you want to delete.
    rmdir PATH
    remove folder with command prompt
  3. Press Enter to finish the process

For example, to delete a folder named “Info” on your desktop, use the following command where you will replace username with your own username:

rmdir “C:UsersusernameDesktopInfo”

After you press Enter the folder named “Info” on your desktop will be deleted.

If you want to delete all the files and subfolders in the folder you want to delete, add the /s parameter. This will ensure that the folder is removed including the subfolders and files in it.

Conclusion

As you’ve noticed, commands to delete files and folders in Windows 10 can be pretty handy if you have trouble deleting them the regular way.

Post Views: 9,291

  1. Delete a Folder With Its Contents Manually Through the Command Line
  2. Delete a Folder With Its Contents Using a Batch File

Delete a Folder With Its Contents Using a Batch File in Windows

Deleting folders along with their content can be easily done through Windows Explorer. But, if the files or folders are larger, it will be time-consuming; a folder larger than 5GB in size will take at least 5 to 10 minutes to completely erase.

The fastest way to delete files and folders is through the command line. We can either do it manually using the cmd or create a Batch file.

This tutorial will teach you how to delete folders and subfolders using a Batch file.

Delete a Folder With Its Contents Manually Through the Command Line

The rmdir command is used to delete a directory (folder), the same as the rd command. It removes the specified folder along with its subfolders and files.

The syntax of the rmdir command is shown below.

rmdir [/s [/q]] [<drive>:]<path>

Parameters:

  • [<drive>:]<path> — specifies the location of the folder.
  • /s — deletes the specified folder and its subfolders and files.
  • /q — specifies Quiet mode. It does not prompt for a confirmation when deleting a folder, and it will only work if /s is specified.

To delete a folder and its contents manually, open the command prompt through the Start menu or search bar. Copy the command as shown below.

The following code uses the rmdir command to delete a directory tree.

rmdir /s /q D:TESTFOLDERtest

Delete Folders Using CMD

Change the destination path to the folder location that you want to delete. The folder will be deleted along with its content.

Delete a Folder With Its Contents Using a Batch File

Rather than deleting folders manually using the command line, we have a one-click solution by creating a Batch file to delete the folders automatically. After the Batch file is created, you can run the Batch file whenever you need to delete a folder.

A Batch file is used to execute commands in a serial order stored in a plain text file. It is saved with the .bat extension.

Here, we have a folder named test1 with subfolders and files. In this article, we will use this folder as an example.

Test Folder

Delete a Single Folder With Its Contents

To create a batch file, open Notepad from the Start menu and copy the commands as shown below:

echo Delete folders using a batch file
rmdir /s /q D:TESTFOLDERtest1

Delete a Folder Using a Batch File

Save the file with a .bat extension.

Bat File

Now, run the file by double-clicking on it to delete a folder and its content. The above command will delete the specified directory along with its content.

We can also delete multiple folders using a Batch file by adding the paths of the different folders. Here, we have two folders named test1 and test2, which we will take as an example.

Test Folders

Delete Multiple Folders With Its Contents

Open Notepad and copy the commands shown below:

echo Delete folders using a batch file
rmdir /s /q D:TESTFOLDERtest D:TESTFOLDERtest1

Delete Multiple Folders

Save the file with a .bat extension, and run the .bat file by double-clicking.

So, we discussed how to delete a folder and its content manually using cmd and a Batch file. Using the Task Scheduler application, you can use Batch files to perform repetitive tasks, automate tasks, or even schedule tasks.

Like this post? Please share to your friends:
  • Windows cannot complete installation in safe mode
  • Windows cannot communicate with the device or resource primary dns server
  • Windows cannot be installed to this disk this computer s
  • Windows cannot be installed to this disk gpt partition style
  • Windows cannot be installed on this drive