How to delete a file, directory, or folder
https://www.computerhope.com/issues/ch000743.htm
Last updated
https://www.computerhope.com/issues/ch000743.htm
Last updated
Updated: 12/01/2019 by Computer Hope
The steps to delete a computer file, directory, or folder vary on the method you'd like to use, as well as your operating system. To proceed, choose from the list of options below and follow the instructions.
Microsoft Windows users can delete a file or folder (directory) using many different methods. Below are the more common methods for deleting a file or folder.Note
Users not familiar with Windows should realize that if you delete a folder, it deletes all the files and folders within that folder.Tip
The steps below are for deleting a single file or folder. However, the same steps can be done to delete multiple files or folders if you select more than one file.
Locate the item you want to delete, highlight it by clicking on the file or folder once, and press the keyboard delete key. You can browse to the location of the file or folder using either My Computer or Windows Explorer.Tip
You can delete multiple files or folders by holding down the Ctrl key and clicking each before pressing Delete.Tip
Open My Computer or Windows Explorer. Locate the file or folder you want to delete and right-click it. Choose the delete option from the pop-up 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 the Alt key to make the menu bar visible, including the file menu.
Some files 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 a read-only file, meaning it can only be opened for viewing, but it cannot be modified or deleted. When trying to delete a read-only file, you'll get a message stating the file is write-protected and cannot be deleted. You'll need modify or write permissions to be granted to your user account 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 be able to delete the affected file or folder.
See the below MS-DOS and Windows command line section for information about deleting a file or folder at the Windows command line.
See our uninstalling a program steps for help with uninstalling (deleting) software programs from the computer.
If you've deleted a file by mistake, you can see our steps on how to restore a deleted file page for further information on recovering a deleted file.
Note
Keep in mind that any deleted file or directory in MS-DOS is not be sent to the Windows Recycle Bin.
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 this command could be used.
As seen in the above example, when deleting a file, you need to enter the full file name including the file extension.Tip
The del command can be used to delete any file.
You can also use wildcards if you want to delete multiple files as shown in the example below.
In the above example, this command would delete all files that end with a .txt file extension.Tip
The del command can be used to delete any file extension.
MS-DOS users can delete directories 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 this could be used.
Note
If the directory is full or has other subdirectories, you'll 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.
If you want to delete a directory within another directory (subdirectory), you can use a command similar to the example below.
In the above example, 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.
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.
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 be used to delete any file.
Linux and Unix users can delete files through the console by using the rm command. See this page for additional information about this command. Below is an example of how this command could be used.
As seen in the above example, when deleting a file, you need to enter the full file name including the file extension.Tip
The rm command can be used to delete any file.
You can also use wildcards if you want to delete multiple files as shown in the example below.
In the above example, this command would delete all files that end with a .txt file extension.Tip
The rm command can be used to delete any file of file extensions.
Linux and Unix users can delete folders through the console by using the rmdir command. See this page for additional information about this command. Below is an example of how this command could be used.
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.
If you want to delete a directory within another directory (subdirectory), you can use a command similar to the example below.
In the above example, 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.
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.
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 be used to delete any file.
Apple macOS users can delete a file or folder (directory) 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 if you delete a folder, it deletes all the files and folders within that folder.Tip
The steps below are for deleting a single file or folder. However, the same steps can be applied to delete multiple files or folders if you select several of them first.
The delete key on the keyboard by itself will not delete a file or folder on macOS. To delete a file or folder hold down the command key and press the delete key at the same time. You can browse to the location of the file or folder using Finder.
Open Finder and locate the file or folder you want to delete and right-click the file. From the right-click menu that appears, click the Move to Trash option.
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.
To delete files or directories in the Terminal command line, use the rm command.
Open File Manager
Locate the folder or file you want to delete, then click File and Delete.
See the above MS-DOS user section for information about deleting a directory in MS-DOS.
You can hold down the Shift key while pressing the delete key to prevent the files being deleted from going to the Recycle Bin.
Before any of the steps below can be followed, 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 go through our how to use the Windows command line (DOS) tutorial.