I had to delete 8 millions files and folders. Opening up Windows Explorer and hitting delete key would take days to delete the whole directory structure. Killer of this deletion is ENUMERATION. That’s right, it takes forever to enumerate directory structure and file.
I came up with Power Shell command that can delete the whole directory structure quick and painless. Even “Remove-Item” command-let does the same thing as like GUI. So I decided to start deleting the forth-level directories (with files) and up. The command I used is,
Get-ChildItem | Get-ChildItem | Get-ChildItem | Get-ChildItem | Remove-Item –Force –Recurse
The above piped command took about a day to delete. I was amazed. Use this command on the power shell on the root directory.
Explanation: Get-ChildItem lists the child directory and second Get-ChildItem list the grand-children directories. In the end, we start deleting the from forth-level directories and slowly start deleting to level up.