Delete files and folders in c:\windows\temp

Marius - Roma 391 Reputation points
2025-03-15T16:14:20.06+00:00

In a Windows 11 PC the c:\windows\temp folder contains dozens of folders whose names look like tmpxxxxxxx.

Based on the date new folders are created every few days.

I am member of the Administrators group but I cannot open neither delete any of such folders.

I attempting changing the owner with no success.

How can I delete them in order to save space?

The local Administrator user is disabled and I don't want to enable it if not strictly necessary...

Regards

Windows for business Windows Client for IT Pros User experience Other
{count} votes

Accepted answer
  1. Anonymous
    2025-03-17T09:00:11.4333333+00:00

    Hi,

    Please open properties of the folder and check the permission in the security tab. Make sure the administrator group have the full control permission to the folder. To take owner of the folders, open cmd as administrator and run

    takeown /f "C:\Windows\Temp\tmpxxxxxxx" /r /d y
    

    If the issue persists, you can reboot your computer to safe mode and try deleting the folders again.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2025-03-22T15:11:53.4433333+00:00

    I am member of the Administrators group but I cannot open neither delete any of such folders.

    That's because the explorer process does not run elevated. While your account is a member of the administrators group, you're still just a "user" until you elevate to get admin access. The default NTFS permissions on temp don't grant users read access.

    Cleanmgr should be removing old files.

    If you open a cmd or powershell prompt with "run as administrator" you can then delete the files.

    In an admin Powershell prompt, you can play with this command to select how old a file has to be to be eligible for deletion. (Change the "10" to the desired number of days.)

    Get-ChildItem -Path c:\windows\temp -File | Where-Object {($_.LastWriteTime -lt  ((Get-Date).AddHours(-(24*10)))) }
    

    You can then delete the files by piping them to remove-item. I would recommend that you do some analysis on file names and file age and think about what those files are from and if you should delete them or not.

    Get-ChildItem -Path c:\windows\temp -File | Where-Object {($_.LastWriteTime -lt  ((Get-Date).AddHours(-(24*10)))) } | remove-item -Verbose -whatif    
    

    Remove the -whatif switch to actually delete the files. Whatif is great for testing.

    That won't remove empty folders, but it will delete files that occupy the disk space.

    WARNING! Be very very careful when deleting files anywhere in c:\Windows. When Powershell first came out, I had to restore a VM twice because the application owner (who had admin access) was playing with Powershell and twice he deleted almost every file in system32.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.