In general, a Windows 10/11 computer is known to come up with “File in Use” or “File is Locked for Editing” error, if any User tries to delete a Shared File that is being used by another User.
As you will agree, this feature in Windows operating system is useful, as it has been specifically designed to protect Shared Files from being mistakenly deleted.
However, it is not uncommon to find Windows preventing a File/Folder from being deleted, even if the File/Folder was created by a User having full rights or permission to View, Edit and Delete Files.
In such cases, you should be able to delete the Locked File or Folder using Command Prompt with Admin Privileges.
Delete Locked File Using Command Prompt
If you are unable to delete a File or Folder on your computer due to File is Locked error, you can find below the steps to delete Locked File using Command Prompt.
1. Delete File Using Command Prompt
Any File, located anywhere on the computer can be deleted by running Del/FolderPath\FileName.extension Command in the Command Prompt window.
1. Right-click on the Locked File that you want to delete and select Properties in the drop-down menu.
2. On the Properties screen, switch to Details tab and note down the Folder Path.
In this case, the Locked File Test.rtf is located at Folder Path C:\Users\Username\Desktop.
3. Next, type CMD or Command in the Search bar > right-click on Command Prompt in the search results and select Run as Administrator option.
4. On the Command Prompt screen, type del FolderPath\FileName.extension and press the Enter key.
Once the Command is executed properly, the File will be immediately force deleted and removed from your computer.
2. Delete Locked Folder Using Command Prompt
Similarly, any Folder located anywhere on the computer can be deleted by running rmdir /s /q FolderPath\FolderName Command.
1. Right-click on the Locked Folder that you want to delete and select Properties option in the drop-down menu.
2. On Properties screen, you will find the Folder path listed next to the Location Entry.
3. Next, open Command Prompt as Admin > type rmdir /s /q FolderPath\FolderName and press the Enter Key.
Once the Command is executed, the Folder will be immediately Force Deleted and removed from your computer.