How do I find and delete all files without a file extension and delete them?

Butler, Blake 20 Reputation points
2024-03-25T17:57:02.9533333+00:00

I'm working with a recovery database that recovered data from a plex server. The data produced thousands of files with a GUID name without an extension. I want to just wipe all these files out and delete the subfolders.User's image

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,035 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 31,561 Reputation points
    2024-03-25T22:37:16.73+00:00

    Here's a script to start with.

    $path = "c:\temp\zzzz"
    $files = Get-ChildItem -Path $path -File -Recurse | Where-Object -Property Extension -eq ""
    "We found {0} files." -f $files.count
    $files | Remove-Item -whatif
    $dirs = Get-ChildItem -Path $path -Directory -Recurse | Sort-Object -Property Fullname -Descending   # process subfolders first
    foreach ($dir in $dirs) {
        $dir.FullName
        $contents = Get-ChildItem $dir.FullName
        if ($contents.count -eq 0) {                  # delete empty folders 
            $dir.FullName
            $dir | Remove-Item -WhatIf
        }
    } 
    

0 additional answers

Sort by: Most helpful