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»:
After that, you’ll see a Command Prompt window with administrative privileges:
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:
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:
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:
To get around this, use the /f
flag to force delete the file. For example, del /f "Read Only Test File.txt"
:
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
:
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:
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:
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.
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:
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:
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:
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.
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"
The above command will remove the “New folder” only if it is empty. If a folder has subdirectories, you might get the following prompt:
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"
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"
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"
For directories:
rd "Folder1" "Folder3" "Folder5"
Here is a before and after comparison of the directory where both of the above commands were executed:
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"
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:
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)
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:
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:
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:
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:
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.”
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).
The Windows Command Processor cmd.exe
has two internal commands for deletion of files and folders:
- The command DEL is for the deletion of files with usage help output on running in a Windows command prompt window either
help del
ordel /?
. - 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
orrmdir /?
orhelp rd
orrd /?
.
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
-
1
Locate your file. If you know where the file is, you can navigate to it by simply opening the appropriate folder. For example, if you’re trying to delete a picture or a text file, you will likely want to look in the default «Documents» folder, which typically holds those file types.
- If you don’t know where your file is, type its name into the Start search bar, right-click the file when it pops up, and click Open file location to go directly to the file.
-
2
Click and drag your file onto the desktop. Doing so will make the deletion process easier as you won’t have to change the deletion location from within Command Prompt.
- The exception to this rule is if you’re trying to delete a file from the «System32» folder, which is Windows’ system files folder. If that’s the case, leave your file there.
Advertisement
-
3
Right-click your file. This will prompt a drop-down menu.
-
4
Click Properties. It’s at the bottom of the drop-down menu.
-
5
Look at the file extension. The file’s extension is listed near the top of the «General» tab in the «Properties» window, to the right of the «Type of file:» text. You’ll need to know your file’s extension in order to delete it using Command Prompt. Common extensions include the following:
- .txt — Text files (files made in Notepad).
- .docx — Microsoft Word files.
- .jpg or .png — Picture files.
- .mov, .wmv, .mp4 — Video files.
- .mp3, .wav — Sound files.
- .exe — Executable files (e.g., a setup file).
- .lnk — Shortcut files. Deleting a shortcut will not remove the attached program from your computer.
-
6
Write down the file extension. Once you know the file extension, you’re ready to open and use Command Prompt.
Advertisement
-
1
Open Command Prompt. In this case, you’ll want to avoid the «Administrator» (or «Admin») version of Command Prompt unless you’re deleting a file in the «System32» folder. You can open Command Prompt in a variety of ways depending on your version of Windows:
- Hold down ⊞ Win and press X, then click Command Prompt above the Start button.
- Right-click the Start button in the bottom-left corner of the screen, then click Command Prompt in the pop-up window.
- Type «Command Prompt» into the Start menu search bar (for Windows 8, hover your mouse in the top-right corner of the screen and click the magnifying glass), then click the «Command Prompt» icon when it appears.
- Open the «Run» app from the Start menu, type in «cmd», and click OK.
-
2
Type in cd desktop and press ↵ Enter. Doing so will change the location (or «directory») in Command Prompt to your desktop.
- There are other ways you can change the Command Prompt directory if need be.
- Opening Command Prompt in «Administrator» mode will change the directory to the «System32» file. For this reason, do not open Command Prompt in «Administrator» unless your file is in the «System32» folder.
-
3
Type in del [filename.filetype]. Replace «filename.filetype» with your file’s actual name and extension.
- For example, a picture file named «icecream» would become icecream.png, a text file named «notes» would become notes.txt, and so on.
- For files with spaces in their names, place quotation marks around the entire file name: "I like turtles.jpg" instead of I_like_turtles.jpg or similar.
- To delete all files on your desktop that share the same extension (e.g., all text files), type *.filetype where «filetype» is the extension (e.g., *.txt).
-
4
Press ↵ Enter. You will see a new, blank line appear in Command Prompt. Your file is now gone.
- Since the «del» command removes files directly from your hard drive, you won’t need to delete the file again from the Recycling Bin.
Advertisement
Add New Question
-
Question
What is the extension type of a folder?
Only files have extensions. Directories are handled differently by the filesystem, and thus do not need extensions.
-
Question
Some type of virus installed to my PC and won’t let me use Command Prompt. What should I do?
Try running an antivirus program to eliminate the virus. If that doesn’t work, you’ll probably need to take your computer in to a tech department somewhere (e.g., Best Buy) and have them take a look at removing the virus.
-
Question
When I typed «cd desktop» in Command Prompt’s Administrative mode, it shows «the system cannot find the path specified». What should I do?
You should open Command Prompt in its non-Admin format—e.g., «Command Prompt» instead of «Command Prompt (Admin)». Since Command Prompt (Admin) opens inside of the «System32» folder, you won’t be able to open the desktop from there (because the «Desktop» folder is under your name in the «Users» folder, not in the «System 32» folder).
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
-
It is recommended that you use your system’s file manager to delete files and only use Command Prompt when it is needed to delete files that require a more forceful approach.
Thanks for submitting a tip for review!
Advertisement
-
If you delete a system file, your computer might cease to work.
-
Using Command Prompt to delete files will entirely bypass the Recycling Bin.
Advertisement
About This Article
Article SummaryX
1. Right-click the Start menu.
2. Click Command Prompt.
3. Type «cd FOLDERTHATCONTAINSFILE» and press Enter.
4. Type «del filename» and press Enter.
Did this summary help you?
Thanks to all authors for creating a page that has been read 982,679 times.
Is this article up to date?
Improve Article
Save Article
Improve Article
Save Article
In some cases, for whatever reason, Windows will make sure that the provided file is used by the system and prevent it from being deleted. This file situation is very frustrating, especially if you know the file is not in use.
If you are having trouble in deleting any file or folder directly by right-clicking, then you can delete it using cmd. The commands below delete the specific file or folder and place them in the recycle bin:
- del
- rmdir
Here we have created a sample File and a Folder to delete it using CMD:
del command
del command is used to delete a file. Here, we will take our sample file “hello.txt” located at the desktop and try to delete it using the del command in CMD. Follow the steps given below to delete the file:
Step 1: Change the path of the directory in CMD and set it to the path of the file. Type the following command in cmd and press Enter:
cd desktop
Step 2: Delete the file “hello.txt” with following command:
del hello.txt
rmdir command
rmdir command is used to delete the entire folder or directory. Here, we will take our sample folder named “Tasks” placed at desktop and try to delete it using rmdir command in CMD. Follow the steps given below to delete the folder:
Step 1: Change the path of the directory in CMD and set it to the path of the folder. Type the following command in cmd and press Enter:
cd desktop
Step 2: Delete the folder “Tasks” with following command:
rmdir tasks
Updated: 02/07/2022 by
Now and then, it is a good idea to clean up your drives and delete duplicate photos, documents, temporary files, shortcuts, videos, or other unneeded or unused files or folders. The steps to delete a computer file, directory, or folder vary on the method you want to use and your operating system. To proceed, choose from the list of options below and follow the instructions.
How to delete files in Microsoft Windows
Microsoft Windows users can delete an unwanted file or folder (directory) from a hard drive or external disk drive using many different methods. Below are the more common methods for deleting a file or folder in Microsoft Windows.
Note
Users not familiar with Windows should realize that if you delete a folder or directory, all files and folders in that folder or directory are deleted.
Delete key
Locate the item you want to delete, highlight it by left-clicking the file or folder with your mouse once, and press Delete. You can browse the location of the file or folder using My Computer or Windows Explorer.
Tip
You can delete multiple files or folders by holding down Ctrl and clicking each file or folder before pressing Delete.
Tip
You can hold down Shift while pressing Delete to prevent files from going to the Recycle Bin when deleted.
Delete file or folder by right-clicking
Open My Computer or Windows Explorer. We recommend you make sure the directory or folder is empty before proceeding, unless you intend to delete everything in it. Locate the file or folder you want to delete and right-click it. Choose the Delete option from the pop-up menu.
How to delete from the local disk
Important
The local disk contains files and folders that are imperative for your computer to run correctly. Unless you know what you are deleting, please do not delete any files from this section.
Open My Computer or Windows Explorer. On the left side of the screen, click This PC. On the right side of the screen, locate and double-click the local disk (usually C: or D:). Double-click the folder containing the file you want to delete. Select the file or folder you want to delete, click File in the top menu bar, and select Delete.
How to delete from an external drive
To delete from a USB flash drive, floppy drive, memory card, or external hard drive, open My Computer or Windows Explorer. On the left side of the screen, click This PC. On the right side of the screen, locate and double-click the drive, which is labeled as USB, flash drive, external hard drive, or the manufacturer’s name. Select the file or folder you want to delete, click File in the top menu bar, and select Delete.
Delete from the file menu
Open My Computer or Windows Explorer. Locate and select the file or folder you want to delete, click File in the top menu bar, and select Delete.
Tip
If the File menu is not visible in My Computer or Windows Explorer, press Alt to make the menu bar visible, including the file menu.
Problems during delete
Some documents and folders may be protected from deletion through encryption or password protection. In this case, you may be asked for a password to decrypt or remove the password protection.
A file may be set as read-only, meaning the user can only open it for viewing and not modify or delete it. When trying to delete a read-only file, you get a message stating the file is write-protected and cannot be deleted. You need to modify or write permissions to delete the file.
Some files may only be deleted with administrator permissions. To delete these files, you would need to have administrator rights on the computer. If you are using a work computer, the technical support staff often are the only users with administrator rights on the computer.
Another possible cause of problems with deleting a file or folder is a virus or malware infection. Viruses and malware can prevent files or folders from being modified or deleted. If this is the case, you need to remove the virus or malware infection to delete the affected file or folder.
- Unable to delete file: being used by another person or program.
- How to remove a virus and malware from my computer.
Windows command line
See the MS-DOS and Windows command line section below for information about deleting a file or folder at the Windows command line.
Uninstalling a program
See our uninstalling a program steps for help with uninstalling (deleting) software programs from the computer.
- How to uninstall software in Windows.
How to restore a deleted file or folder
If you’ve deleted a file by mistake, you can see our page on how to restore a deleted file for further information on recovering a deleted file.
- How to recover missing, lost, or deleted files.
How to delete files in MS-DOS and the Windows command line
Note
Keep in mind that any deleted file or directory in MS-DOS is not sent to the Windows Recycle Bin.
Before you follow any of the steps below, you must get to an MS-DOS prompt or the Windows command line. If you are new to the command line, you may also want to read through the following pages first.
- How to get to an MS-DOS prompt or Windows command line.
- How to use the Windows command line (DOS).
Files
MS-DOS users can delete files using the del command. See this page to get additional information and help with this command. Below is an example of how to use this command.
del example.txt
As seen in the example above, when deleting a file, you need to enter the full file name, including the file extension.
Tip
The del command can delete any file.
Delete multiple files
You can also use wildcards to delete multiple files or a group of files, as shown in the example below.
del *.txt
In the example above, this command would delete all text files that end with a .txt file extension.
Tip
The del command can delete any file extension.
Directory
MS-DOS users can delete directories (dir) in MS-DOS using the deltree command or rmdir command. See either of these links for additional information about these commands. Below is an example of how to use this.
rmdir example
Note
If the directory is full or has other subdirectories, you get an error message. To delete a full directory, you need to use a switch with the above example. For example, «rmdir example /s» to remove a full «example» directory. See our deltree command or rmdir command for additional examples and switches.
- How to delete files in MS-DOS without a prompt.
Deleting a subdirectory
To delete a subdirectory, subfolder, folder within a folder, or directory within a directory, use a command similar to the example below.
rmdir exampletest
In the example above, the «test» directory in the «example» directory is deleted. You could also use the cd command to change the directory to the example directory and then delete the «test» directory using our first example shown above.
How to delete a directory or file name with a space
To delete a directory or file name with a space in the name, you must surround the directory or file name with quotes, as shown below.
del "my example file.txt"
rmdir "my example directory"
In the above examples, we are deleting the file named «my example file.txt» with quotes surrounding the complete file name and extension and removing the «my example directory» directory.
Tip
The rmdir command can delete any file.
- How to use the Windows command line (DOS).
How to delete files in Linux, Unix, and other variants
Files
Linux and Unix users can delete files through the console using the rm command. See this page for additional information about this command. Below is an example of how to use this command.
rm example.txt
As seen in the example above, when deleting a file, you need to enter the full file name, including the file extension.
Tip
The rm command can delete any file.
Delete multiple files
You can also use wildcards if you want to delete multiple files, as shown in the example below.
rm *.txt
In the example above, this command would delete all files with a .txt file extension.
Tip
The rm command can delete any file of file extensions.
Directory
Linux and Unix users can delete folders through the console with the rmdir command. See this page for additional information about this command. Below is an example of how to use this command.
rmdir example
Tip
Like Microsoft Windows, with Linux and Unix, you can also delete files through the GUI by locating the file and pressing the delete key on the keyboard.
Deleting a subdirectory
To delete a directory in another directory (subdirectory), use a command similar to the example below.
rmdir exampletest
In the example above, the «test» directory in the «example» directory would be deleted. You could also use the cd command to change the directory to the example directory and then delete the «test» directory using our first example shown above.
How to delete a directory or file name with a space
To delete a directory or file name with a space in the name, you must surround the directory or file name with quotes, as shown below.
rm "my example file.txt"
rmdir "my example directory"
In the examples above, we are deleting the file named «my example file.txt» with quotes surrounding the complete file name and extension. We are also removing the «my example directory» directory.
Tip
The rmdir command can delete any file.
- How to remove a full directory in Linux.
- Linux and Unix shell tutorial.
How to delete files on macOS
Apple macOS users can delete photos, documents, or other files or folders (directory) on their Mac using many different methods. Below are the more common methods for deleting a file or folder.
Note
Users not familiar with Apple macOS should realize that it deletes all the files in a folder if you delete that folder.
Delete key
The delete key on the keyboard by itself does not delete a file or folder on macOS. To delete a file or folder, press and hold Command, then press delete. You can browse to the location of the file or folder using Finder.
Right-click and choosing Move to Trash
Open Finder, locate the file or folder you want to delete, and right-click the file or folder. In the right-click menu that appears, click the Move to Trash option.
Delete from the file menu
Open Finder, locate and select the file or folder you want to delete. Click File in the top menu bar and select Move to Trash.
Terminal
To delete files or directories in the Terminal command line, use the rm command.
How to delete files on Microsoft Windows 3.X
File Manager
- Open File Manager
- Locate the folder or file you want to delete, then click File and Delete.
MS-DOS
See the MS-DOS user section above for information about deleting a directory in MS-DOS.