Force Delete a File or Folder by CMD in Windows 10/8/7

User Author

Achilles.H

June 25, 2021

Force Delete a File or Folder by CMD in Windows

If you fail to delete a file or folder, and get the prompt "This action cannot be completed because the folder or file is open in another program", you can try two ways to solve the issue.

Way 1. Close the program that opens the file or folder, and then delete the file or folder. For more details, see Folder or file is open in another program how to do?

Way 2. Use command to force delete files. Note: This way can't delete a folder when it is opened by another program. The following guide will show you how to force delete a file.

1. Run the command prompt as Administrator: Start->Search "cmd" -> Right click cmd.exe -> Click "Run as Administrator".

run cmd as administrator

2. The file location after cd is the location where the file or folder..

cd command

3. Use the command "del /s/f/q" to force delete files.

force delete a file

Noted: This command deletes files that are opened with read-only mode. I tried to delete a RAR file that was being opened by 7z, but I failed. I also tried to delete an exe file that was running, but it couldn't work. So, the best way to force delete a file or folder opened by another program is to close the associate program, and then delete the file or folder. For more details, read the article Folder or file is open in another program how to do? or Run Windows to safe mode to delete files or folders.

fail to force delete file