1

I'm trying to search for a certain file extension, .pro. I have tried the following searches in the search bars: type:.pro and *.pro, however, both of these queries yield files with the extension .properties and .project. I don't want these in my results. how do I exclude these?

tuskiomi
  • 798
  • 2
  • 10
  • 25
  • If you use `cmd` and `dir *.pro /s` you will find the results you want, though maybe not in the format you might have wanted them. – AFH Jun 11 '17 at 22:22
  • @AFH this search still yields .properties, .providers, and .project files. – tuskiomi Jun 11 '17 at 22:26
  • I'm sorry, you're right, and I've just realised why: Windows still insists on providing 8.3 names for long file names, including those with long extensions. Unfortunately all the name massaging is done in the 8-character part and the 3-character extension is the first 3 characters of the long extension. In its wisdom `dir` matches both long and short file names, hence your result. You can disable 8.3 names or you can use `findstr` to filter the results (as I now see David Postill has suggested in his answer). – AFH Jun 11 '17 at 22:53
  • @AFH [dir command matchs both short and long names for a reason](https://superuser.com/q/238900/241386). [Why does FindFirstFile find short names?](https://blogs.msdn.microsoft.com/oldnewthing/20050720-16/?p=34883) – phuclv Jun 12 '17 at 02:33
  • @LưuVĩnhPhúc - Your links explain the mechanism, but not the reason for it, especially now that Windows 10 appears not to support 16-bit programs. There is another solution: [TCC/LE](https://jpsoft.com/all-downloads/downloads.html) is a replacement for `cmd`, which is extended to give near-Unix scripting power, but more or less maintains `cmd` compatibility for existing scripts; by default its `dir` command does _not_ match 8.3 names, though there is an option to allow this. TCC/LE is free for non-commercial use, and is a slightly stripped-down version of the even more powerful TCC. – AFH Jun 12 '17 at 10:11
  • @AFH It's exactly the reason cmd cannot remove those features because 32-bit Windows 7 and 8 can still run 16-bit programs. Old batch scripts also rely on those behavior, like `dir *.txt` being exactly the same as `dir .txt` so MS can't remove them from 64-bit cmd either. Moreover you don't need any replacement, powershell can do all of that and match Unix behavior. Simply abandon cmd altogether – phuclv Jun 12 '17 at 10:13
  • @LưuVĩnhPhúc - Point taken. All I can add is that for a `cmd` user TCC is a lot easier to learn than PowerShell. – AFH Jun 12 '17 at 10:18
  • another duplicate: [Windows command line search for exact extension with dir](https://stackoverflow.com/q/2423935/995714) – phuclv Jun 12 '17 at 10:18

1 Answers1

2

I'm trying to search for a certain file extension, .pro

I have tried the following searches in the search bars: type:.pro and *.pro, however, both of these queries yield files with the extension .properties and .project.

This is not possible using the Windows Explorer search bar, even when using Advanced Query Syntax.

However, it can be achieved in a cmd shell, with the following command:

dir /b /s | findstr /e /l /c:".pro"

Example:

> dir /b /s *.pro
F:\test\.pro
F:\test\test.pro
F:\test\test.profile
F:\test\test.properties
F:\test\test.project

> dir /b /s | findstr /e /l /c:".pro"
F:\test\.pro
F:\test\test.pro

Further Reading

DavidPostill
  • 153,128
  • 77
  • 353
  • 394