October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Redmond desk3 min

Delete a Locked File in Windows CMD: What Works and What Doesn’t

DEL /F can delete a read-only file, but not one held open by another process. Check the path, identify and close the owning process, then retry DEL.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

del /f in Command Prompt can delete a read-only file, but it cannot unlock a file that another program is using. For an in-use file, find the process holding it open, close that process safely, and then retry the deletion. First confirm the exact file path: Microsoft warns that a file deleted with del cannot be recovered through the usual Recycle Bin workflow.

Before deleting a file from Command Prompt

del deletes files directly, so check the target before running it. Open Command Prompt and inspect the folder with dir, quoting any path that contains spaces:

As an Amazon Associate I earn from qualifying purchases.

dir "C:pathtofolder"

Microsoft advises checking which files match a wildcard with dir before using that wildcard with del. Avoid broad wildcards and the recursive /s switch unless you intend to delete matching files in subfolders as well. See Microsoft’s DEL command reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Delete a read-only file with DEL /F

Try a normal deletion first. Replace the example path with the verified file path:

#1 Best Overall
del "C:pathtofolderfile.ext"

Add /p if you want Command Prompt to ask for confirmation before deleting:

del /p "C:pathtofolderfile.ext"

If the file has the read-only attribute, use /f:

del /f "C:pathtofolderfile.ext"

Microsoft documents /f as forcing deletion of read-only files. It is not a general unlock switch: it does not release a process’s open handle, fix access permissions, or repair file-system corruption.

If Windows says the file is in use

A file held open by another process may not be deletable until that process releases its handle. Microsoft’s NTFS file and folder troubleshooting guide recommends determining which process is using the file and closing it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Close the application normally

If you recognize the application, save any work and close it normally. Then retry del. This is the safest first option because it lets the application release the file handle cleanly.

Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.

Find the process holding the file

Microsoft Sysinternals Process Explorer can search for processes holding particular handles. The command-line Handle utility displays open file references and requires administrative privileges. Use one of these tools to identify the process before deciding whether it is safe to stop.

Stop a known-safe process from CMD

Use tasklist to inspect running processes and identify the correct process ID (PID):

tasklist

After verifying the PID and that the process can safely be closed, end it with taskkill:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
taskkill /pid 1234

1234 is an example only; substitute the verified PID. Microsoft documents taskkill as ending tasks by PID or image name. Its /f option forces termination, while /t also ends child processes. Forceful termination can lose unsaved work or disrupt other activity, so do not use it broadly or against a process you have not identified. After the process closes and releases the handle, retry del. See the TASKKILL command reference.

Rank #3
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the fix that matches the error

What is happening What to do Important limitation
The file is read-only Try del /f "C:pathtofile.ext". /f is for read-only files; it does not resolve an open handle.
Another program is using the file Identify and close the owning application or process, then retry del. Stopping the wrong process can disrupt work or lose unsaved changes.
You need to end a process from CMD Verify the process with tasklist, then use taskkill with its PID or image name. /f forcefully ends it; /t also ends child processes.
The file still cannot be deleted Diagnose the specific error, including permissions or possible file-system problems. DEL switches are not a universal repair for access-control issues or corruption.

DEL switches to use carefully

Microsoft documents this syntax: del [/p] [/f] [/s] [/q] [/a[:]<attributes>] <names>. In practical terms:

  • /p prompts before each file is deleted.
  • /f forces deletion of read-only files.
  • /s deletes matching files from the current directory and its subdirectories.
  • /q suppresses confirmation.
  • /a selects files by attributes.

Wildcards are supported, but they can match more files than expected. Inspect the matches with dir before using them with del, and avoid adding /s unless recursive deletion is intended.

When deletion still fails

If the process has been closed and the file still will not delete, do not keep adding force switches. Read the exact error and distinguish an open-handle problem from an access-control issue or a possible file-system problem. Microsoft’s NTFS troubleshooting guide discusses corruption as another reason deletion may fail; the right next step depends on the specific error and condition.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$245.99
Bestseller No. 2
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$285.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.