n0rd
n0rd

Reputation: 12620

`dir` to consider only long file names

Up till now I thought if I do dir *.aaa I will get all files with extension .aaa, following proves me wrong:

echo >a.aaa
echo >a.aaa_bbb
dir /b *.aaa

prints

a.aaa
a.aaa_bbb

Which is not quite what I expect. I guess this is because a.aaa_bbb's name in 8.3 notation has the .aaa extension. How do I force dir not to consider 8.3 names? Or please suggest any other way to list files by file mask that does not consider 8.3 names.

UPD: Thank you. Can't mark both answers as accepted, but they both are good.

Upvotes: 3

Views: 189

Answers (2)

foxidrive
foxidrive

Reputation: 41234

Here is one way:

dir *.aaa /b |findstr /i "\.aaa$"

or this: (double the % to %% for use in a batch file)

for %a in (*.aaa) do if /i "%~xa"==".aaa" echo %a

Upvotes: 4

Stephan
Stephan

Reputation: 56180

forfiles /M *.aaa does the trick. There are many parameters to change the output to your needs. See forfiles /?

Upvotes: 4

Related Questions