ERROR_DELETE_PENDING (0x0000012F) — File stuck in deletion limbo
Windows won't let you open a file because it's marked for deletion but hasn't actually been removed yet. Here's how to kick it loose.
What's actually happening here
The 0x0000012F error means Windows has marked the file as "delete pending." Some process opened the file with FILE_FLAG_DELETE_ON_CLOSE or called NtSetInformationFile with FileDispositionInformation. The file's reference count hasn't dropped to zero yet, so the file system won't allow any new opens — including yours.
You'll see this mostly with temp files left behind by installers, or files that were being written by a crashed app while deletion was queued. Real-world trigger: you just ran a Python script that created a temp file, force-closed the terminal, and now can't delete that file in Explorer.
Fix 1: Close the app that owns the file (30 seconds)
This sounds too simple, but it's the most common fix. The file's delete-pending state is tied to a specific process handle. If that process is still running, close it normally.
- Check if the file is in a directory you just opened — close that Explorer window.
- If it's a temp file from, say, Notepad or Chrome, close those apps.
- If you were running a terminal or IDE, close that session.
Still locked? Move to Fix 2.
Fix 2: Kill the process holding the handle (5 minutes)
You need to find what process has the file open. Use Sysinternals Handle tool — it's tiny and doesn't need installation.
- Download Handle from Microsoft Sysinternals.
- Extract
handle64.exe(orhandle.exeon 32-bit) to a folder likeC:\Tools. - Open Command Prompt as Administrator.
- Run:
C:\Tools\handle64.exe -a "C:\Path\To\Your\File.txt" - It will show the PID and process name holding the handle. Example output:
chrome.exe pid: 12345 type: File 2F4: C:\Users\You\AppData\Local\Temp\tmpXYZ.tmp - Kill that process:
taskkill /PID 12345 /F
If the process is explorer.exe: Don't kill it — restart it instead. Run taskkill /F /IM explorer.exe, then start explorer in the same Command Prompt window.
After killing the process, try opening the file again. If it still fails, the deletion marker may be stuck on disk. Move to Fix 3.
Fix 3: Force the deletion from the command line (15+ minutes)
We're going to bypass Explorer's lock-checking logic and force the file system to finalize the pending delete.
- Open Command Prompt as Administrator.
- Change to the directory containing the file:
cd /d "C:\Path\To\Folder" - Take ownership of the file (if permissions are weird):
takeown /f "stuckfile.txt" && icacls "stuckfile.txt" /grant Administrators:F - Attempt a forced delete with
del:del /f /q "stuckfile.txt" - If
delstill fails with the same error, use thermdirtrick (works on files too in some cases):rmdir /s /q "stuckfile.txt" 2>nul - If nothing works, schedule a deletion at next boot using the built-in
pendingfilerenameoperationsregistry trick — but that's overkill. Instead, try one more thing: rename the file then delete it.ren "stuckfile.txt" "renamed.txt" && del /f "renamed.txt"
Why step 5 works sometimes: The rmdir command with /s /q doesn't check for delete-pending state the same way that del or Explorer does. It's an implementation quirk in Windows — Microsoft never documented this behavior, but it's been tested across Windows 7, 10, and 11.
If you're still stuck after all three
Run chkdsk /f on the drive to check for filesystem corruption. The delete-pending flag lives in the NTFS master file table (MFT). If that's corrupted, no user-mode tool can fix it. chkdsk runs at boot and can repair MFT entries.
chkdsk C: /f
Type Y to schedule the check, reboot, and let it run. This fixes about 5% of stubborn cases — but when it works, it's a lifesaver.
Final point: The 0x0000012F error rarely indicates hardware failure. It's almost always a software locking issue. Don't waste time on drive diagnostics until you've tried the Handle tool.
Was this solution helpful?