C:\Windows\WinSxS\Temp\InFlight\ Deleting Empty Folders


Tester

Active member
Member
Local time
2:17 AM
Posts
192
OS
Windows 11
Hi,

I am testing and making a powershell script to delete empty folders in C:\Windows\WinSxS\Temp\InFlight\
To my understanding when updates or other windows operations occur, files in use might be placed there, and upon a restart they will be cleared.
On a lot of systems, i have thousands (some 10k, some over 100k) of empty folders in C:\Windows\WinSxS\Temp\InFlight\
While only 1 or a few folders actually has files inside it. The one folder with the most current date.
All the other folders are from dates when windows update did install updates, but after the reboot after the windows update the folder itself was not deleted.

I want do this, because during backup/sync/virus/malware scan operations on different systems i see a few min delay in processing all those empty folders. So i tought i am going to test this on a few systems, if it gives any problems to delete those empty folders.

I will be doing these operations on some virtual machines i use daily, with an snapshot to revert back to. Will be testing this for about one month, before pushing this to live machines.

Most search records i find online is, do not touch the WinSxS folder...

Anyone who has experience with this, or has been testing around with this? Any toughts about doing this?

1739536895909.webp
 
Last edited:

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Why are you not using Dism /online /cleanup-image /StartComponentCleanupcommand i would not mess with those files in that folder?

 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
I do use that command every few months on systems, but that does not clear the empty folder issue in /Temp/InFlight/ for me. Does it for you?
And not going to do things with files in that folder, only empty folders in the /Temp/InFlight/ folder.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
Storage Sense, also does not delete those empty folder for me. It does delete it for User Temp folder, and Windows Temp folder for me. But not the \WinSxS\Temp\ folder. Does this work for you?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
I never have checked as i have plenty of disk space to worry about few MB of temp files.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
For me it is not about the diskspace it takes up. But processing time it takes.
If you have for example 300systems, and backup needs to process those folders for a few minutes on all those systems, it takes over a hour of processing time all combined. So if you backup 300systems, x lets say 50k empty folder for \WinSXS\Temp\InFlight\ per system, you end up processing 15.000.000 empty folders. While if it was possible to delete them every month or so, it would not have to process them...
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
I just use
to reduce SxS and System32, run in admin prompt:
Code:
DISM /Online /Cleanup-Image /StartComponentCleanup /resetbase

My backups (granted for only 1 system) are lightning fast.
24H2 is/has been much better with SxS than older versions.
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2 current-1mo, build a/o 2-13-25: 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
You can delete the C:\Windows\WinSxS\Temp\InFlight folder by executing the following commands.

Batch:
takeown /F C:\Windows\WinSxS\Temp\InFlight /r

icacls C:\Windows\WinSxS\Temp\InFlight /grant Administrators:F /T

rd /s /q C:\Windows\WinSxS\Temp\InFlight
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
You can delete the C:\Windows\WinSxS\Temp\InFlight folder by executing the following commands.

Batch:
takeown /F C:\Windows\WinSxS\Temp\InFlight /r

icacls C:\Windows\WinSxS\Temp\InFlight /grant Administrators:F /T

rd /s /q C:\Windows\WinSxS\Temp\InFlight

I do it about the same now in powershell, but in the temp\InFlight\ folder are also files located, and those files i don't want to delete for obvious reason. And want to leave the normal permission on folders with files in side it, so i am only resetting the rights with empty folders. Slower.. but i guess safer.

A part of my code, will post full code, when i am done.

Powershell:
        foreach ($folder in $emptyFolders) {
            # Take ownership and grant permissions
            try {
                takeown /f "$($folder.FullName)" /r /d y
                icacls "$($folder.FullName)" /grant administrators:F /t
            }
            catch {
                Write-Warning "Failed to take ownership or grant permissions for $($folder.FullName).  Error: $($_.Exception.Message)"
                continue
            }
            try {
                Remove-Item -Path "$($folder.FullName)" -Recurse -Force -Confirm:$false
                $deletedFolderCount++
            }
            catch {
                Write-Warning "Failed to delete folder $($folder.FullName). Error: $($_.Exception.Message)"
            }
        }
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
My backups (granted for only 1 system) are lightning fast.
24H2 is/has been much better with SxS than older versions.

Can you go to c:\windows\WinSXS\Temp\ and then right click InFligh foldert, and see how many files and folders are in there?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Good luck then i show you a way to delete temporary folder rest is up to you.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
Good luck then i show you a way to delete temporary folder rest is up to you.
Thanks for the tip! Because not all people know how to take ownership, as it was needed on those files, and not all know how to do that. But in this case i did! I appreciate your guidance.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
One initial test i did. Right click Window folder to show properties, and then stopwatch time until all folders and files where counted.
This was done in a test vm.
Before cleanup empty folders: +/45sec to count all files and folder.
1739542973921.webp
After cleaup, it took 16seconds to count all files and folder:
16 sec vmware_cWKV1Eo86u.webp

Only c:\windows\WinSXS\Temp\InFlight\ Folder:
vmware_marjcsw6sj.webp


Will try to do an malware scan and see if times has improved with malwarebytes on the c:\Windows folder with before cleanup and after cleanup.
 
Last edited:

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
There's this script, which handles the folder permissions in a more correct fashion:
@MyITGuy MyITGuy/Invoke-WinSxSTempCleanup.psm1

Some folks are bound to suggest DISM++, but since it's not open source, I wouldn't run that on my company's production systems.

Thanks! I will take a look at that script. At first glance it looks like an eleganter solution as taking owership.
I also have seen a few system, that also have PendingDeletes that are there for over a year. But before deleting i first need to understand why that is happening.

Have used DISM++ in the past. Think that app is chinese?

Malwarebytes scan, before cleanup 10m 4s:
1739546543265.webp

After cleanup 4m 2sec:
1739546561185.webp

I guess my assumption was right that those empty folders are slowing down scan. I guess backup would improve on there speed as well.

Now going to test if windows update, dism and other functions are not trowing errors.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Have used DISM++ in the past. Think that app is chinese?
Whether the current dev team is based in China is immaterial. It's a closed source project, but they're not a vendor or a software foundation which takes direct responsibility for the app. The standards for running an outside app in a workplace is different from your personal desktop.
 

My Computer

System One

  • OS
    Windows 7
Whether the current dev team is based in China is immaterial.
That's right. I'm based in Ohio, and I wouldn't trust my code either.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
Removing /s parameter from RD command should only delete empty directories.

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Latest Support Threads

Back
Top Bottom