Get all files with a specific extension

Garry White

I am trying to get a file with a specific extension from a directory. To do that I am using the following batch file code:

for %%f in (.\*.ext) do (
     echo %%f
)

This works fine, unless I have a file with .extsomething extension.
I tried adding the $ wildcard to get only the exact matching, but it doesn't show any results with it.

for %%f in (.\*.ext$) do (
     echo %%f
)

Since the * wildcard is accepted, why the $ is not considered?
How can I get only the files with the exact extension?

Gerhard

Just add an if statement:

@echo off
for %%f in (*.ext) do (
    if "%%~xf"==".ext" echo %%f
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get a list of all files with a specific extension?

How can I get the path of all files with specific extension

Symfony Finder: Get all the files with a specific extension and all the directories within a specific directory

Find all files that are NOT of a specific type/extension in folder?

How to remove all files with specific extension in folder?

Remove a specific extension from all the files in a directory

Loop through all the files with a specific extension

Find all files by extension excluding specific directories

How can i get all files on disk with a specific extension using 'Directory.getFiles' and save them in a list

How do i get a list of all files with a specific extension with c++ without <dirent.h> on windows

Add suffix to all files without specific extension and retain the file extension

Using R to read all files in a specific format and with specific extension

Get the total size of all files of a given extension

Recursively execute all files with a specific extension via command line

How to configure prettier to check all files with a specific extension

show specific lines from all files with .txt extension

show a group of specific lines from all files with .txt extension

gitignore, track all files with some extension, except one specific file

How to add a launcher that opens all files with a specific extension in XFce?

Copy all files with specific extension from remote server with Java

List all files with specific extension beneath a directory in Scala

Delete all subfolders and files except for a specific extension inside parent folder

reading all the files in a directory with specific extension using glob python

Remove last line from all files of a specific extension

Perforce sync all files with a specific extension to revision #0

Visual Studio 2013 / Open all files of a specific extension

How to get all the files in a specific folder?

How to get the list of files of specific extension in bash in just one line?

Get a list of filenames without extension for all files in a directory