.netpowershelldelete-fileenumeration

File Operation without enumeration


I want to delete a huge amount of files via PowerShell. I want to use a terminal, because my Explorer crashes if I try to delete or access the folder.

It is an INetCache folder from Windows ("C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache\IE") same for system32.

With the good old cmd I was able to see what is actually in the folder, and there are ~10gb of 0.5 - 1.5 kbit *.htm files. (~8 million files)

Can I use / Are there .net libs for file operations that do not enforce enumerations? all I found in ps is, that most programs are just aliases to .net lib based programs. otherwise I would have to rely on a *.bat file...

Maybe I oversee an easy solution?

What I tried:

Everything I executed from the PowerShell against the directory froze the session. I think this is because the programs try to enumerate the contents of the directory.

Solutions:


Solution

  • Just to add to this, in my experience in a Windows Server 2012 R2 trying to delete the system32 inetcache (>15 million files), the erase *.* command from the old cmd.exe (don't use powershell) is the only approach that begins deleting files from the first moment (checked with sysinternal's procmon.exe).

    Other alternatives began with a full scan of the files, and just performing a "dir *.*" took 15 hours so it didn't seem like a good approach, specially since I needed to delete in small time slots because the disk queue went too high and greatly affected system performance.