- How To Delete Files & Folders – From The Windows Command Line (CMD, DOS)
- Jump Right In:
- Navigating To The File Using CMD.
- Deleting Folders / Directories Using CMD.
- Deleting Files Using CMD.
- Creating a dummy file with a specific size.
- Delete Many Files Or Folders At Once.
- Delete Files Or Folders From Any Directory.
- What We’ll Learn:
- Navigating To The File Using CMD:
- Deleting Folders / Directories Using CMD
- Deleting Files Using CMD
- Delete Many Files Or Folders At Once — From CMD
- Delete Files Or Folders From Any Directory (CMD)
- Summary:
- That’s It!
- Delete Folder using cmd on Windows 10- Clear files using Terminal
- Jump to:
- Delete a Folder using cmd(Command prompt) on Windows 10- Easy Steps:
- How to Delete files of a folder using Command Prompt on Windows 10:
- Conclusion of the Article:
- How to delete all files and folders in a folder by cmd call
- 12 Answers 12
- Delete files or folder recursively on Windows CMD
- 12 Answers 12
- Use the Windows rmdir command
How To Delete Files & Folders – From The Windows Command Line (CMD, DOS)
Jump Right In:
Navigating To The File Using CMD.
Deleting Folders / Directories Using CMD.
Deleting Files Using CMD.
Creating a dummy file with a specific size.
Delete Many Files Or Folders At Once.
Delete Files Or Folders From Any Directory.
What We’ll Learn:
Welcome!
This guide is all about deleting files and folders from the windows command line.
- We’ll start by learning, how to navigate the file or folder we want to delete form the command prompt.
- How to use the Del and Rmdir commands to remove files and folders respectively.
- How to take advantage of wildcards to perform an operation on multiple files or directories.
- And finally, we’ll learn how to delete files and folders without navigating to the directory in which they are located.
Lets get started!
Navigating To The File Using CMD:
To delete a file or folder using the command prompt we must first navigate to the location of our file.
By default the command line is located at a folder named after your computers username (C:\Users\MyPC). This folder contains your documents, downloads and desktop directories, among others.
To view all the files in this directory use the “Dir” command, which stands for directory.
Every file in this directory will be displayed at once.
If the file or directory you want to delete is located at your desktop for example use the “Cd” command to change the command prompts directory.
Simply type “Cd” followed by the folder you want to navigate into within quotes.
You will at once navigate into the desktop directory and from here you can use the “Dir” command once again to locate the file or folder you want to delete.
If you navigated to the wrong directory by mistake, type:
You will immediately be navigated into the previous directory.
In a similar way you can use a combination of the “Dir” and “Cd” commands to navigate to any directory and locate any file or folder.
Deleting Folders / Directories Using CMD
To delete a folder use the “Rmdir” command, which stands for “Remove Directory”.
Keep in mind that as the name suggests, “Rmdir” only deletes directories. Trying to delete a file using “Rmdir” will constitute in an error.
You might be wondering why we surrounded the name of our folder in quotes. The quotes tell the command line that the spaces separating the words do not constitute an additional parameter and that they are simply a part of the name of our folder.
“Rmdir” without any parameters only removes folders that are empty, to delete a folder along with the files or folders within it you need to use the /S parameter.
The command would look like this:
After entering the command the command line will ask if you are sure you want to delete this file. Simply press “ y ” to confirm.
If you want to delete a folder in a directory other than your users folder you would need to start the command prompt as an administrator. Be careful when deleting folders with administration privileges, the wrong command can very easily break your computer.
Deleting Files Using CMD
The command for deleting files using the cmd is “Del“. Unlike “ Rmdir “, “ Del “can only delete files. Using “ Del ” to delete a folder will constitute in an error .
To delete a file simply type “Del” followed by the name of your file along with its extension in quotes.
Your file should be immediately deleted.
Once again if you file is not located in the users folder or within any of its sub-directories you would need to start the command prompt as an administrator.
Be very careful however , the wrong command in an administrator command prompt can very easily break your computer.
To delete more than one file at once simply enter all the names of your files one after the other.
Delete Many Files Or Folders At Once — From CMD
Entering the name of every file or folder you want to delete is not always practical.
Work smarter not harder.
You can delete every file that begins with a set of characters by using a wildcard.
Wildcards are special symbols that take the place of characters or words.
The most commonly used wildcard is the asterix.
Typing “Del” followed by a set of characters that is shared among the names of the files we want to delete and an asterix, will delete all of them.
Every file that begins with the word “File” will be deleted.
To delete a set of folders instead, simply replace the Del command with Rmdir.
Similarly you can delete only files of a specific type by specifying its extension before a wildcard. With the following command for example, we can delete every text file in our current directory.
We can even delete every file or folder by using a wildcard, all by itself.
Here is an example using the Rmdir command:
Every folder in your current directory will be deleted along with any contents within it.
Be careful when deleting files and folders, the wrong command can easily delete important files and folders.
Delete Files Or Folders From Any Directory (CMD)
While you can use the “Rmdir” and “Del” commands to delete files and folders in your current directory, what if you want to delete a folder or file that’s located in a different directory without having to navigate there yourself?
You would have to enter your command as usual but instead of typing the name of the file or folder you want to delete directly you would have to enter the location of the target directory followed by a backward slash and then name of your folder or file.
It should look something like this:
In the same way you can replace “Rmdir” with any command to complete any task from any directory.
Summary:
- Navigate to the directory the file you want to delete is located with the “CD” and “Dir” commands.
- Use “Rmdir” to delete folders and “Del” to delete files. Don’t forget to surround the name of your folder in quotes if it contains a space.
- Use wildcards to delete many files or folders at once.
That’s It!
You now know how to delete files and folders directly from the command prompt.
If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.
Delete Folder using cmd on Windows 10- Clear files using Terminal
Delete folder using cmd on Windows 10 Operating System: It is been a long way for the Operating systems which earlier used commands on terminal to control the machine. But then a total revolution happened with the arrival of Windows that totally changed the purpose and usage of an Operating system. In spite of all the latest GUI provided by various Operating systems like Windows, Linux, and Mac, each of them is loaded with the Terminal shell with which the operating system can be used to its core functionality which tells us the importance of the Command Terminal even after all these years. This is a simple article explaining How to Delete a Folder using cmd on Windows 10.
Jump to:
Delete a Folder using cmd(Command prompt) on Windows 10- Easy Steps:
Let us get into the steps directly.
- Open Run Command box using the shortcut Windows key + R.
- Type cmd and click on OK. Command Prompt will open now.
- The command to remove a folder as follows.
How to Delete files of a folder using Command Prompt on Windows 10:
Here in this section, we will see How to Delete the files of a folder. Kindly follow the below steps.
Example: del -f C:\Users\TecKangaroo\Desktop\testfolder\testfile
The above command will ask for the confirmation before deleting the file.
Conclusion of the Article:
This is a Tutorial that will help you to delete folders and files using Command Prompt. With the arrival of Graphical User Interface on Operating systems, a lot of operations and applications have been made way simpler and it is very easy to delete a file or folder on Windows 10 using GUI. However, if you face any problem in that, then you can use this tutorial method to delete the folder using cmd and delete files using cmd.
If you have any questions, please leave us a comment. Stay tuned for more awesome posts on the latest technology.
How to delete all files and folders in a folder by cmd call
I want to delete all files and folders in a folder by system call.
I may call like that:
Do you know an easier way?
12 Answers 12
No, I don’t know one.
If you want to retain the original directory for some reason (ACLs, &c.), and instead really want to empty it, then you can do the following:
This first removes all files from the directory, and then recursively removes all nested directories, but overall keeping the top-level directory as it is (except for its contents).
Note that within a batch file you need to double the % within the for loop:
del c:\destination\*.* /s /q worked for me. I hope that works for you as well.
I think the easiest way to do it is:
The last «\» in the path is the important part.
Yes! Use Powershell:
If the subfolder names may contain spaces you need to surround them in escaped quotes. The following example shows this for commands used in a batch file.
To delete folder with all files in it:
To delete all files from specific folder (not deleting folder itself) is a little bit complicated. del /s *.* cannot delete folders, but removes files from all subfolder. So two commands are needed:
You can create a script to delete whatever you want (folder or file) like this mydel.bat :
Few example of usage:
One easy one-line option is to create an empty directory somewhere on your file system, and then use ROBOCOPY (http://technet.microsoft.com/en-us/library/cc733145.aspx) with the /MIR switch to remove all files and subfolders. By default, robocopy does not copy security, so the ACLs in your root folder should remain intact.
Also probably want to set a value for the retry switch, /r , because the default number of retries is 1 million.
I had an index folder with 33 folders that needed all the files and subfolders removed in them. I opened a command line in the index folder and then used these commands:
I separated them into two lines (hit enter after first line, and when asked for more add second line) because if entered on a single line this may not work. This command will erase each directory and then create a new one which is empty, thus removing all files and subflolders in the original directory.
Delete files or folder recursively on Windows CMD
How do I delete files or folders recursively on Windows from the command line?
I have found this solution where path we drive on the command line and run this command.
I have given an example with a .svn file extension folder:
12 Answers 12
The other answers didn’t work for me, but this did:
/q disables Yes/No prompting
/s means delete the file(s) from all subdirectories.
Please execute the following steps:
- Open the command prompt
- Change directory to the required path
Give the following command
You can use this in the bat script:
Now, just change c:\folder a to your folder’s location. Quotation is only needed when your folder name contains spaces.
ex. RMDIR «C:\tmp» /S
Note that you’ll be prompted if you’re really going to delete the «C:\tmp» folder. Combining it with /Q switch will remove the folder silently (ex. RMDIR «C:\tmp» /S /Q )
For file deletion, I wrote following simple batch file which deleted all .pdf’s recursively:
Even for the local directory we can use it as:
The same can be applied for directory deletion where we just need to change del with rmdir.
If you want to delete a specific extension recursively, use this:
You could also do:
The /p will prompt you for each found file, if you’re nervous about deleting something you shouldn’t.
After the blog post How Can I Use Windows PowerShell to Delete All the .TMP Files on a Drive?, you can use something like this to delete all .tmp for example from a folder and all subfolders in PowerShell:
Use the Windows rmdir command
That is, rmdir /S /Q C:\Temp
I’m also using the ones below for some years now, flawlessly.
Check out other options with: forfiles /?
Delete SQM/Telemetry in windows folder recursively
Delete windows TMP files recursively
Delete user TEMP files and folders recursively