- Command windows delete files from
- Errorlevels
- Undeletable Files
- Permanent deletion
- Delete Locked files
- How to delete files and folders using Command Prompt in Windows 10
- Delete files & folders using Command Prompt
- 1] Delete the desired file
- 2] Delete the desired folder
- How to Delete a File in Windows (several variants)
- Contents
- Delete file to “Recycle Bin”
- How to delete a file (folder) using the menu
- How to delete a file (folder) using the button
- Disable (enable) delete confirmation
- How to recovery files from Recycle Bin
- How to empty Recycle Bin
- How to permanent Delete
- Guaranteed file deletion
- Guaranteed deletion of data on the active disk
- Guaranteed data deletion on inactive devices
- Delete via the Command prompt
- How to delete a file via command prompt
- How to delete a folder via command prompt
- Delete via PowerShell
- Comparison table of options how to delete a file
- [How To] Simple Commands to Delete Files in Windows
- Command to Delete Files
- 1. Command to delete a single file
- 2. Delete multiple files with a command
- 3. Command to delete files with a specific extension
- 4. Delete read-only file with Command Prompt
- Wrapping Up
Command windows delete files from
Delete one or more files.
If a folder name is given instead of a file, all files in the folder will be deleted, but the folder itself will not be removed.
Errorlevels: DEL will return an Errorlevel of 0, irrespective if the delete succeeds or fails for any reason.
Also a deletion failure will not fire for || unless the DEL arguments are invalid.
If you delete files using PowerShell then a True/False return code ( $? ) will be set correctly.
Errorlevels
If the files were successfully deleted %ERRORLEVEL% = 0
If the files failed to delete, or don’t exist to be deleted %ERRORLEVEL% = 0
Bad or no parameters given %ERRORLEVEL% = 1
Undeletable Files
Files are sometimes created with a very long filename or a trailing period or with reserved names (CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL) and as a result they become impossible to delete with Windows Explorer.
To delete such files use the syntax: DEL «\\?\path to file»
You can also use «\\.\path to device «
e,g,
DEL «\\?\C:\some folder\AZH64GT.»
DEL «\\.\C:\Work\LPT1 «
Alternatively for long filenames, you can reduce the total path length by using SUBST to map a drive letter to the folder containing the file.
It is also possible to delete long paths using RoboCopy — Copy/Move the required files to a temporary folder and then delete the folder, one gotcha with that technique is RoboCopy’s tendency to follow symbolic links which can cause files outside the source folder to be moved/ deleted.
If a file is still ‘undeletable’ this may be caused by the indexing service, temporarily stop the service and then delete the file.
Permanent deletion
Deleting a file will not prevent third party utilities from un-deleting it again. Secure file deletion utilities are available, however for casual use, you can turn any file into a zero-byte file to destroy the file allocation chain like this:
TYPE nul > C:\examples\MyFile.txt
DEL C:\examples\MyFile.txt
Delete Locked files
Typically this is caused by the Offline Cache or Internet Explorer temp files.
Close all applications
Open a command prompt
Click Start, and then Shut Down
Simultaneously press CTRL+SHIFT+ALT.
While you keep these keys pressed, click Cancel in the Shut Down Windows dialog box.
In the command prompt window, navigate to the cache location, and delete all files from the folder (DEL /s)
At the command prompt, type explorer, and then press ENTER.
DELTREE — Older versions of Windows had the DELTREE command to delete all files and sub folders. This can be replicated with a script as shown on the DELTREE page.
Delete «Hello World.txt»
DEL «Hello World.txt»
Delete 3 named files:
DEL file1.txt file2.txt «C:\demo\file3.txt»
Delete all files that start with the letter A
Delete all files that end with the letter A
Delete all files with a .doc extension:
Delete all read only files:
Delete all files including any that are read only:
Normally DEL will display a list of the files deleted, if Command Extensions are disabled; it will instead display a list of any files it cannot find.
DEL is an internal command. ERASE is a synonym for DEL
“But over all things brooding slept, The quiet sense of something lost”
DELPROF — Delete user profiles.
DELTREE — Script to Delete a folder and all subfolders/files.
RD — Delete folders or entire folder trees.
CleanMgr — Automated cleanup of Temp files, Internet files, downloaded files, recycle bin.
FORFILES — Delete files older than X days.
INUSE — updated file replacement utility (may not preserve file permissions)
Q120716 — Remove Files with Reserved Names.
Q320081 — You cannot delete a file or folder.
Q159199 — A file cannot be deleted (NTFS)
PowerShell: Remove-Item — Delete the specified items.
Equivalent bash command (Linux): rmdir / rm — Remove folders/ files.
How to delete files and folders using Command Prompt in Windows 10
At times, all our attempts to delete files or folders via File Explorer yield no results. Many reasons can be attributed to the failure, which can lock down the files/folders and prevent their deletion. In such cases, you can use the Command Prompt to delete files, folders, and subfolders.
Delete files & folders using Command Prompt
First things first, using the Command Prompt incorrectly may render your system inoperable, and at the time you will not be able to recover deleted files. So proceed carefully and exercise extreme caution.
There are multiple ways via which you can delete a file or a folder on your Windows system. It is possible that you’ll run into problems if the file is locked. This is where the Command line prompt finds its real utility.
To delete files using Command Prompt, make sure to open it with admin privileges.
1] Delete the desired file
When the CMD window opens, navigate to the folder where the file is available. You will have to use the “cd” or change directory command. Then, use the following command with options in the prompt:
Here:
- /F stands for force delete
- /A selects only the files with ready for archiving attribute
2] Delete the desired folder
Navigate to the folder containing the folder you wish to delete by using the ‘cd’ command. Type the following command in the Command Prompt:
Here:
- RD removes the folder from the directory.
- /S Removes all subfolders and files
If you use the /Q parameter also, then you will not be asked for the Y/N confirmation.
If the folder or file is locked, you can follow these instructions to delete locked or undeletable files & folders.
Try this and let us know in the comments section below if the method works for you.
How to Delete a File in Windows (several variants)
This basic guide describes in detail how to delete a file (folder) in Windows (several ways): from simple deletion to guaranteed deletion with protection from data recovery programs.
Contents
Delete file to “Recycle Bin”
💡 To select multiple files or folders, hold the special button and press the left mouse button:
- Сtrl — highlight a specific file or folder;
- Shift — selection of a range of files or folders.
How to delete a file (folder) using the menu
- Right-click on a document or folder;
- Select the Delete item;
- Click Yes in the confirmation request.
The file will be deleted to the Recycle Bin.
How to delete a file (folder) using the button
- Highlight a document;
- Press the Del key;
- Click Yes in the confirmation request.
The file will be deleted to the Recycle Bin.
Disable (enable) delete confirmation
- Click on the Recycle Bin can icon with the right mouse button;
- Select Properties;
- Disable the Display delete confirmation dialog.
💡 If you just deleted the desired file, press the key combination Ctrl + Z. This will undo your last action in Windows, the deleted file or folder will return to its place.
How to recovery files from Recycle Bin
- Open the Recycle Bin;
- Select the desired file or folder;
- Right click on the selected file;
- Select Recover.
Restore files
The file will be restored to the folder from which it was deleted.
You can transfer the file (or folder) from the Recycle Bin to the folder you need.
Click and hold the left mouse button on the selected file and drag it to the folder or Desktop you need.
How to empty Recycle Bin
You can delete all files from the Recycle Bin.
- Click on the Recycle Bin with the right mouse button;
- Click Empty Recycle Bin.
Empty Recycle Bin
How to permanent Delete
- Highlight a file or folder;
- Press the key combination Shift + Del;
- Click Yes in the confirmation request.
Permanently delete folder
Guaranteed file deletion
Guaranteed deletion of data on the active disk
For guaranteed data deletion, we use the standard CIPHER utility.
Cipher.exe is a command-line tool (included with Windows 2000) that you can use to manage encrypted data by using the Encrypting File System (EFS)
💡 To overwrite as much data as possible, it is recommended that you close all other applications while running CIPHER / W.
- Run the command prompt as administrator;
- We launch the CIPHER command with the necessary keys.
/W — key, deletes data from available unused disk space in the entire volume. The content is overwritten in three stages, with values: 00, FF and a random number.
:X — work volume label.
Utility Cipher.exe
Guaranteed data deletion on inactive devices
For guaranteed data deletion on inactive devices: unused hard disks, portable hard disks and flash devices, we use the standard FORMAT utility.
- Run the command prompt as administrator;
- We start the format command with the necessary keys.
X – specifies the drive letter (followed by a colon), mount point, or volume name.
/P:count — zero every sector on the volume. After that, the volume will be overwritten “count” times using a different random number each time. If “count” is zero, no additional overwrites are made after zeroing every sector.
To run the utility successfully, you must enter the correct label of the active volume/device.
Utility Format.com
The process can take a long time, especially if a large number is indicated in the rewrite counter.
Delete via the Command prompt
How to delete a file via command prompt
- Run the command prompt;
- Go to the desired folder (cd command);
- Run the del command and the fully qualified file name with the extension.
If there are spaces in the file name, enclose the name in quotation marks.
To delete files from system directories, you must run the command prompt as administrator.
How to delete a folder via command prompt
- Run the command prompt;
- Go to the desired folder;
- Run the RD command.
/S – removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.
If there are spaces in the directory name, enclose the name in quotation marks.
To delete directory from system directories, you must run the command prompt as administrator.
Delete via PowerShell
The PowerShell command to delete folders and files is Remove-Item.
The synonyms of the Remove-Item command are: del, erase, rd, ri, rm and rmdir, so commands from the Windows command prompt will also work.
Windows PowerShell
X – full path to the file (with extension) or folder.
Recurse – the key indicating the deletion of the content folder.
Comparison table of options how to delete a file
Comparison table on how to delete files and folders.
Deleting data to the Recycle Bin | Deleted data can be restored from the Recycle Bin folder on the Desktop. |
Permanent data deletion | Deleted data can only be restored using special programs. |
Guaranteed data deletion | Deleted data cannot be recovered even by special data recovery programs. But special services and laboratories can still recover deleted data. |
How to delete a file (folder) in Windows was discussed in this article. I hope that now you can delete files or folders in different ways, including guaranteed deletion of files beyond recovery with special programs. However, if you run into any problems, do not hesitate to write in the comments. I will try to help.
[How To] Simple Commands to Delete Files in Windows
With simple commands, you can delete any file you want from the Command Prompt. Follow the below steps to learn how.
Using command prompt and PowerShell, you can do almost anything on Windows 10. Deleting a file or a bunch of files is nothing hard. Though you can easily delete files by pressing the Delete key on your keyboard, there might be times when you need to use the commands to delete files.
So, in this short tutorial let me show you the simple commands to delete files in Windows.
Command to Delete Files
When you want to delete something via the Command Prompt, there are multiple scenarios. For instance, you can delete a single file, delete multiple files, delete files with a specific extension, delete read-only files, etc.
To make things easier, I’ve divided the commands into their own sections. Depending on what you are looking for, click on the jump link below to see the command usage.
Jump to delete:
Files deleted via below commands are not moved to the Recycle Bin. i.e, they are deleted permanently. Which simply means that you cannot recover them. So, be careful about what you are deleting.
The del commands shown below will also work with PowerShell.
1. Command to delete a single file
To delete a single file, all you need to do is execute a single command with the file name.
1. First, search for cmd in the start menu, right-click on Command Prompt and select Run as administrator option to open an elevated command prompt.
Note: You can delete files without admin privileges as long as the files belong to your user account.
2. Now, use the cd command to go to the folder where the files you want to delete are located. For instance, the files I want to delete are in a folder named “del” on my desktop. So, I use the following command.
Once you are in the folder, simply execute the below command to delete a file. Don’t forget to replace with the actual file name along with its file extension. In my case, the file name is image-1.jpg .
When you successfully delete a file, you will not see any confirmation message. However, if there is any problem, the command prompt will show an error message.
2. Delete multiple files with a command
There are two ways to delete multiple files in the command prompt. In the first method, you will specify all the file names manually. This gives you better control over the files you delete. The second method is to use the wildcard. This is useful for bulk delete operations.
2.1 Specify file names manually
When you have multiple specific files to delete, you can manually specify the file names. The advantage of this method is that you will only delete those files and ignore all others.
1. Just like before, open the Command Prompt and go to the folder where the files to delete are located.
2. Next, execute the below command while replacing , , etc., with the actual filenames. You can specify as many filenames as you want.
2.2 Bulk delete files with a wildcard
To bulk delete files in a folder, you can use * ( wildcard ). The wildcard feature is very useful when you want to delete all files, files with a specific name, files with a specific extension, etc., in a folder.
1. To delete all files in a folder, use the below command.
2. Since you are deleting all the files in a folder, Windows will warn you. Simply type Y and press Enter to confirm file deletion.
3. Delete all files that start with a specific name. The below command will delete all the files with the name that starts with “image”.
3. Delete all files that contain a specific word. The below command will delete all the files with the name that contains “tFile”.
3. Command to delete files with a specific extension
1. If you are looking to delete files that have a specific file extension then you can use the below command. Don’t forget to replace “fileExtension” with the actual file extension, like png, jpg, zip, etc.
For example, to delete all the PNG files in a folder, the command with look something like this.
2. To delete all files with a specific name and file extension, use the below command. Don’t forget to replace the file name and extension to match your needs.
4. Delete read-only file with Command Prompt
Read-only files are protected and are generally difficult to delete, by design. If you try to delete a read-only file via command prompt using the above command, you will receive “Access is denied” error message.
To delete a read-only via the command prompt, you need to force it.
1. Open the command prompt and navigate to where the file is located.
2. Once you are here, use the below command. Replace with the actual filename.
3. As an alternative, you can also use this command to delete read-only files.
Wrapping Up
As you can see, commands to delete files in Windows are pretty simple and straight forward. All you need is a single command and you are good to go.
If you are stuck or need some help, comment below and I will try to help as much as possible.