- Delete files from command line
- How to delete a file
- Delete files in bulk
- Delete multiple files
- Delete Read only files
- 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
- 3 Genius Ways to Delete a File in Use in Windows
- Force Deleting a File in Use in Windows
- More Related Articles:
- From Command Prompt
- Using a Third-Party Tool – Unlocker
- How to Restore a File If It Has Been Deleted Accidentally
- Your Safe & Reliable Data Recovery Software
- Video Tutorial on How to Recover Deleted Files on Windows 10/8/7 Easily?
Delete files from command line
Deleting files is one of the frequently done operation from Windows command prompt. This post explains how to use ‘del’ commandВ from CMD for different use cases like deleting a single file, deleting files in bulk using wild cards etc. Before we start to look at the syntax, note that the command works only for files and can’t handle folders.
How to delete a file
Run del command with the name of the file to be deleted, you are done!
You do not see message after running the command if the file is deleted successfully. Error message is shown only when something goes wrong.
Delete files in bulk
Del command recognizes wildcard(*) and so can be used to deleteВ files in bulk from CMD.В Some examples below.
To delete all the files in current folder
To delete all the files with ‘log’ extension
Delete all files having the prefix ‘abc’
Delete all files having ‘PIC’ somewhere in the file name.
The above are the basic use cases of del command. Continue to read below for non trivial use cases.
Delete multiple files
‘Del’ command can accept multiple files as argument
Delete Read only files
We can’t delete a read-only file using simpleвЂdel’ command. We get access denied error in this scenario.
A read-only file can be deleted by adding /F flag.
Alternatively, we can use the below command too
Is there any batch command to delete all zero byte sized files from cmd.
There is a way to remove folders from the commandline, use “RD” (remove directory), and it has a couple of silent switches, “RD /S /Q C:/Directory” will remove C:/Directory silently, I use this all the time. I think that the directory path has to be in quotations if it contains any spaces.
UAC might want to fight over deleting files, in that case, the command “takeown” to give you ownership of the file first, should get around that.
Sometimes we get an error when we try to delete a File or a folder for no reason , but of course there is a reason.We have many damage file or blocked files.Do not worry if we want to remove the error files or too long path files from our system,here I suggest a smooth way.So use “Long path tool” software and keep yourself.
Well done, I used this when del *1*.*
Will keep this in my reference book. Thanks a lot!
Is there a way to exclude filenames matching a pattern from a delete? For example, I want to delete all files except those whose names are like *xyz*
I am trying to delete csv files in DOS that have a date suffix of earlier
than 2 months ago. I need to do this dynamically, from a batch file.
Is this possible ? Many thanks.
Bethany
I want to delete a file from all the user’s profiles using cmd.
The file is on the desktop.
Name of the file-Hello My Name
I’m writing del %PUBLIC%\Desktop\Hello*My*Name.pdf,but that doesnt seem to work.
I also tried del %PUBLIC%\Desktop\*Hello* but that didnt work too.
Any help is appreciated
c. Using the for loop create 5 text files which start from letter a (ex: a1, a2, a3, a4, a5).
can you help me
create 5 files like this command.
for /l %a in (1 1 5) do mkdir File%a.
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.
3 Genius Ways to Delete a File in Use in Windows
Amy Dennis
Dec 21, 2020 • Filed to: Recover & Repair Files • Proven solutions
When working on Microsoft Windows, how many times have you seen a message telling that the particular file you are attempting to delete is already in use and that the program using the file must be stopped before Windows allows you to remove the file from the PC?
Annoying!! Isn’t it?
Well, not anymore.
Here are the three genius ways that you can use to force delete a file that is in use and Windows doesn’t allow you to remove it normally.
Force Deleting a File in Use in Windows
This method works most of the time. All you need to do is to force terminate the program that is using the file. Assuming that you already know which program is using the file that you want to remove, this is how you delete the file:
Note:В Windows 7 is used here as a reference PC.
Force terminating a process shuts down the entire program and you may lose any unsaved data that any other file that relies on the program may have. It is advisable to save all your work progress before proceeding.
1. On your desktop screen, right-click the taskbar.
2. From the context menu that appears, clickВ Start Task Manager.
3. In the Task Manager box, if not already there, go to theВ ProcessesВ tab.
4. From the displayed list of running processes, right-click the one that you know is using the file that you want to delete.
5. From the context menu, clickВ End ProcessВ orВ End Process Tree. (End process treeВ is clicked here.)
6. On the confirmation box that pops up, click theВ End process treeВ button from the bottom.
7. Once the process has been forcefully terminated, you can easily remove the file as it is no longer used until the process starts running again.
Note:В In some cases, you need to be quick in deleting the file after force terminating the process. This is because some processes are stubborn and even if you terminate them forcefully, they restart automatically after a few seconds.
More Related Articles:
From Command Prompt
This method requires you to open Command Prompt on your Windows PC. For the files used by some local processes (the processes that can be started and closed by a standard – non-administrator user account), opening Command Prompt on a standard user account would suffice. However, if the file is used by any system process, the elevated Command Prompt must be initialized. An elevated Command Prompt is the command window that has all the administrator rights and all the administrative tasks can be performed via commands in its interface.
This is what you need to do:
Note:В A Windows 7 PC is used in this example.
1. On your Windows PC, locate the folder that contains the file in use that you want to delete. (Do not enter into the folder.)
2.В Shift + right-clickВ the folder.
3. From the advanced context menu that appears, clickВ the Open command window hereВ or press theВ WВ key on the keyboard.
Note:В This method does not allow you to open an elevated command window.
Note: To start elevated Command Prompt, click the Start button, type CMD in the search box at the bottom of the Start menu, right-click CMD from the suggested programs’ list, click Run as administrator from the context menu, and on the User Account Control confirmation box, type the password for the admin account (or click Yes if Windows doesn’t ask you for the password) to provide your consent to continue. After the elevated command window opens up, you must use the DOS commands like CD and DIR to locate the directory where the file you want to delete is placed and to check the presence of the file respectively.
4. In the command window, type theВ DEL /F file nameВ command and pressВ EnterВ to force delete the file that is in use.
Note:В In the above command,В the file nameВ must be replaced by the name of the file along with its extension that you want to delete. For exampleВ del /f TestFile.txt.
WARNING!! – A file deleted using the DEL command does not move it to the Recycle Bin but deletes it permanently. Use the DEL command with caution.
5. Once the file is deleted, you can close Command Prompt by clicking theВ CloseВ button from the top-right corner of the window or by typingВ EXITВ in the command window and pressingВ Enter.
Using a Third-Party Tool – Unlocker
Even though you can use any of the two methods described above to remove a file that is in use, a third-party tool such as Unlocker makes your task extremely simple. The best part is that Unlocker is a freeware and is free to download and use. This is how Unlocker works:
Note:В A Windows 7 computer is used for reference.
1. Log on to your Windows PC.
2. Ensure that it is connected to the Internet.
3. Open any web browser of your choice and open your preferred search engine. (Google, Yahoo!, Bing, etc.)
4. Using the search engine, search for Unlocker.
5. Once found, download Unlocker’s installable file and install the program using the normal installation method, or get its portable version.
Note:В Unlocker is installed on this referenceВ PC.
6. After this, locate the file that you want to delete but is in use.
7. Right-click the file.
8. From the context menu that is displayed, clickВ Unlocker.
9. On theВ User Account ControlВ confirmation box, clickВ YesВ to provide your consent to continue launching the program.
10. On the displayed interface, from the available list of files in use, click to select the one that you want to unlock.
11. From the bottom of the interface, clickВ UnlockВ to unlock the file while leaving the corresponding application open. Alternatively, you can also click theВ Kill ProcessВ button to force terminate the running process that is responsible for engaging the file.
12. Once the file is unlocked, you can right-click the file and clickВ DeleteВ from the context menu.
13. ClickВ YesВ on theВ Delete FileВ confirmation box when/if displayed.
How to Restore a File If It Has Been Deleted Accidentally
Even if the file has been forcefully unlocked using any of the methods, it is moved to the Recycle Bin when deleted (except for when deleted using the command line). That being said, restoring the file from the Recycle Bin is simple. This is what you need to do.
1. On your Windows desktop screen, double-click the Recycle Bin’s icon.
2. Once inside theВ Recycle Bin, right-click the file that you want to restore.
3. From the context menu, clickВ Restore.
Note:В If a file has been deleted permanently (e.g. when removed with the DEL command), you need an efficient file recovery software such as RecoveritВ Data RecoveryВ to recover the file back.
Your Safe & Reliable Data Recovery Software
- Recover lost or deleted files, photos, audio, music, emails from any storage device effectively, safely and completely.
- Supports data recovery from recycle bin, hard drive, memory card, flash drive, digital camera, and camcorders.
- Supports to recover data for sudden deletion, formatting, hard drive corruption, virus attack, system crash under different situations.
Although the above-mentioned tricks work almost every time, you must take the utmost care while deleting any file that is in use. Deleting a wrong file may cause consequences like permanent or temporary system failure or data loss. To avoid this, before force deleting your files, make sure you have thoroughly verified the following:
- The file in use does not contain any important data.
- Force terminating the process to unlock the file doesn’t cause any permanent damage to its corresponding program.
- You have backed up the file before deleting it.
- You have tried (and failed) other ways to do what you want to do, and that force deleting the file is the only option left.
Video Tutorial on How to Recover Deleted Files on Windows 10/8/7 Easily?
Recent Videos from Recoverit