A while ago I swapped my main hard disk for a SSD. Now the old one is used as a secondary hard disk, and my OS is a fresh windows install on the main SSD disk.

Nevertheless, there are still huge pagefile.sys and hiberfile.sys on that secondary hard drive. Those are not the ones used by the current windows, as those do exist on C:\.

I tried to attrib -s -h them, but it refused with "Access denied".

Any idea how to delete those old unused system files and reclaim the space?

  • 2
    if all else fails, you can delete them from a linux live disk - say, using unetbootin if you don't want to waste a disk on it – Journeyman Geek Jun 24 '11 at 13:49
  • If you don't need any of the data then formatting the disk should recover the space, but I'm assuming in this case you do. – ChrisF Jun 24 '11 at 14:02
  • 1
    - I do need the data indeed :) – Silvermist Jun 24 '11 at 16:15
  • 1
    - Linux is an option but I'd rather keep that for last, as it sounds like it would take a while to do, and I have 0 experience with unix commands – Silvermist Jun 24 '11 at 16:16
  • Most Linux live-cds boot into a desktop environment, so you just open the file manager and delete your files. Not all, however, automatically mount NTFS partitions. Two that I know of that do mount them are Ubuntu and Centos. – Joe Internet Jun 24 '11 at 17:38

The files are protected using NTFS ACLs. Use takeown to take ownership of them.

| improve this answer | |
  • Takeown worked but I still could not delete. Ran commmand prompt as administrator : F:\>takeown /f hiberfil.sys SUCCESS: The file (or folder): "F:\hiberfil.sys" now owned by user "Me". F:\>attrib hiberfil.sys -s -h Access denied - F:\hiberfil.sys F:\>del hiberfil.sys Could Not Find F:\hiberfil.sys – Silvermist Jun 24 '11 at 16:13
  • 4
    Then also try icacls hiberfil.sys /grant everyone:f - taking ownership doesn't automatically adjust the ACLs. – user1686 Jun 24 '11 at 16:32
  • @grawity, This is odd, If we aren't even booting into C:\ (like right now I'm in UEFI X:\ ), how could these Windows Access Restrictions even stop us? Win8.1 isn't even running, yet I'm getting Access Denied. – Pacerier Apr 24 '15 at 17:39
  • @Pacerier the restrictions are on the file system not on the OS. – RJFalconer Jul 31 '15 at 10:00

Combining the answers it's quite simple, no external programs needed.

From a dos prompt: icacls hiberfil.sys /grant everyone:f to get access to the file attrib -h -s hiberfil.sys to make it visible for deletion del hiberfil.sys to delete the file

For pagefile.sys it works the same way.

| improve this answer | |

Use unlocker to do this. It can not only remove the locking handles that are giving you an "access is denied" message, but can also delete the files at the same time (in case the program tries to reacquire the handle).

| improve this answer | |
  • 1
    In addition to clicking "Unlock All" you can select delete in the Action dropdown. – Kevin Jun 24 '11 at 16:53

I had tried all these methods since migrating my OS to an SSD a year ago. Takeown seems to work, but the file cannot be found to delete, it does not show up doing a DIR from the command prompt, in file browsers, ect... Hiberfil is already disabled via command prompt, but I tried to re-enable it and disable it, still no go.

It was like the file was there, but not there.

What worked for me was creating a 'New > Text Document', Renaming that to Hiberfile.sys. I had to do this in a folder because it would not let me create anything except for a folder in my main F: drive. I then Paste it to F:\, then deleting that file. Freed up the 32GB I had tried to get back a few times over the past year.

| improve this answer | |

If you have only one drive, or you want to maintain the integrity of the files on your secondary drive (i.e. so you could later boot into it if needed), you'll want to disable the pagefile first (steps to disable pagefile from link).

If you don't care about preserving the drive, skip to step 5.

  1. Press Win+R (or Win+S) → enter SystemPropertiesPerformance.exe → press Enter → Click Advanced tab.
  2. Click Change under Virtual Memory and uncheck Automatically manage
    paging file size for all drives.
  3. Click on the partition you are trying to resize and set paging file size to No paging file. Click Set, then OK.
  4. Restart. You'll notice that both pagefile.sys and swapfile.sys are now gone from your disk.
  5. If the page file is still there, use Unlocker to delete the page file on restart.

I'm adding step 5 because the article seems to imply that the page file will disappear as soon as you restart.

This might not always be the case. When I restarted Windows 7 the file was still there. I couldn't delete the file because Windows 7 claimed the file was in use.

TAKEOWN didn't solve the problem either. Unlocker initially said that no locking handle was found.

However, Unlocker did give me an option to delete the file on restart, which worked great. @Kevin, Thanks for suggesting Unlocker.

| improve this answer | |
  • Important parts of this answer is in the link which may go down in future making this answer un-helpful. Please post the contents of the link here & then link back for reference if you want to give credit – pun Jan 27 '16 at 3:04
  • 1
    Thanks for the comment! I'm new to stack exchange - maybe you can tell me if this looks better? – supersolver Jan 28 '16 at 4:45

You probably need to take ownership. And maybe remove the read-only setting? Re taking ownership: this can be achieved manually, but I prefer to add an (extended, hold shift) context menu.

I used the super useful SysInternals tool to locate my entries, F6 takes me to the registry where I can export the entries. You can copy and paste these into .reg files, save then open them to quickly add :)


Windows Registry Editor Version 5.00

@="Take &ownership"

@="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"


Windows Registry Editor Version 5.00

@="Take &ownership"

@="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
| improve this answer | |
  • Can you elaborate on "I used the super useful SysInternals tool to locate my entries"? Which tool? – Syclone0044 May 25 '15 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.