PowerShell: How to Delete Files with No Extension


You can use the following syntax in PowerShell to delete all files with no extension:

Get-ChildItem -File | Where { -not $_.extension } | Remove-Item

This particular example will delete all files in the current directory that have no file extension.

Here is what the various commands do:

  • Get-ChildItem -File: Retrieves all files from current directory
  • Where { -not $_.extension }: Filters for files with no extension
  • Remove-Item: Deletes files with no extension

The following example shows how to use this syntax in practice.

Example: How to Delete Files with No Extension in PowerShell

Suppose that our current directory has the following path:

  • c:\users\bobbi\data2

We can use Get-ChildItem -File to list all files in this current directory:

We can see that our current directory contains the following files:

  • Three files with .txt extensions.
  • Two files with .csv extensions.
  • Two files with no extensions.

Suppose that we would like to delete the two files that have no extensions.

We can use the following syntax to do so:

Get-ChildItem -File | Where { -not $_.extension } | Remove-Item

The following screenshot shows how to use this syntax in practice:

PowerShell delete files with no extension

Notice that when we run the Get-ChildItem cmdlet again to view the updated items in the directory we can see that each file without an extension has been deleted.

Note: You can find the complete documentation for the Remove -Item cmdlet in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Delete All Files with Specific Extension
PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to Get File Extension

Leave a Reply