Take ownership of a file or folder with takeown and icacls
Two-step command sequence that makes you the owner of a locked file tree and grants yourself full control — the standard fix for 'Access is denied' on old profiles and OS reinstall leftovers.
01Command
$ takeown /F "C:\Users\OldProfile\Documents" /R /D Y && icacls "C:\Users\OldProfile\Documents" /grant "%USERNAME%:F" /T02What it does
Access-denied usually means the ACL points at a deleted SID (old profile, rebuilt system); ownership is the only right that overrides the ACL itself, so takeown must run first — as an administrator it can always claim ownership. /R recurses into subfolders and /D Y auto-answers the 'are you sure' prompt (note /D must come last). icacls then grants your account Full control (:F) and /T applies it to every child object. Before changing anything, record the current owner with `icacls "<path>"` so you can restore it; the newer `icacls /setowner` can hand ownership back.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- takeown | Microsoft LearnEvidence: Microsoft documents takeown /F with /R for recursive ownership and /D Y to answer prompts, making the administrator the file owner.
- icacls | Microsoft LearnEvidence: Microsoft documents icacls /grant with the :F permission and /T for applying the ACE recursively to all files and subfolders.
Last verified: 2026-09-17 · Category: Files & Folders
06Related solutions
Windows' built-in tool for overwriting freed disk clusters so previously deleted files can't be recovered — no third-party shredder needed.
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.