PowerShell: How to List All Files in Folder Without Extension


You can use the following syntax in PowerShell to list all files in a particular folder without the file extensions:

(Get-ChildItem).BaseName

This particular example will return all filenames without file extensions in the current directory.

Note that we use the Get-ChildItem cmdlet to retrieve all files in the current directory and then use the BaseName property to extract only the filename itself without the extension.

Note that you could also use the > command to save these filenames to a new file if you’d like:

(Get-ChildItem).BaseName > c:\users\bobbi\my_files.txt

This particular example saves the list of filenames without extensions to a text file named my_files.txt in a specific location.

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

Example: How to List All Files in Folder Without Extension in PowerShell

Suppose that our current directory has the following path:

  • C:\users\bobbi\data2

We can use the Get-ChildItem cmdlet to first view all of the files in this current directory:

We can see that there are three files with .txt extensions in this current directory.

We can use the following syntax to list each of these filenames without their extensions:

(Get-ChildItem).BaseName

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

PowerShell list all filenames without extension

We can see that we were able to successfully list each of the filenames without their extensions.

Note that we could also use the following syntax to save this list of filenames to a text file:

(Get-ChildItem).BaseName > c:\users\bobbi\my_files.txt

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

PowerShell list files without extension and save to new file

Note that when we use the Get-Content cmdlet to view the contents of the file named my_files.txt we can see that it contains the list of filenames from the current directory without the file extensions.

Note: You can find the complete documentation for the Get-ChildItem 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