powershell

How to select files that have no extension using powershell


I have a drive with lots of directories and files, some of which are broken and have no file extension. I would like to delete all of the files that do NOT have an extension. I have tried gci | where {$_.extension -eq ""} and gci | where {$_.extension -eq "."} and variations of those, but end up getting nothing or everything on the drive.

If I look at the results of gci | select Extension the files show nothing for the extension, just like a directory, not sure where to go.

Any help would be appreciated.


Solution

  • gci -File -Recurse | ?{!($_.Extension)}