如何在Windows/命令行/文件打开对话框下匹配确切的文件扩展名? [英] How do you match an exact file extension under Windows/command line/file open dialog?

查看:67
本文介绍了如何在Windows/命令行/文件打开对话框下匹配确切的文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取仅具有给定扩展名的文件的目录列表.乍一看,这似乎很简单,但是请查看以下简单示例:

I am trying to get a directory listing of only files with a given extension. At first blush this seems to be a simple thing to do, however check out this simple example:

C:\CODE\metcal>dir /b *.exe
metcal.exe
metcal.exe1

请注意,这会返回 metcal.** exe ** metcal.** exe1 ** 作为匹配项.

Notice that this returns metcal.**exe** and metcal.**exe1** as matches.

对于python文件,也会发生类似的事情:

With python files a similar thing happens:

C:\CODE\metcal>dir /b *.py
metcal.py
metcal.pyc

再次通知Windows已确定 *.py 接受以 *.py 开头的所有内容,因此它也捕获了 .pyc 文件

Notice again Windows has determined that *.py takes anything that starts with *.py so it captures the .pyc files as well.

有没有办法只获取完全匹配的扩展名?在上面的python文件示例中,我希望发生以下情况(显然用* .py替代了正确的语法)

Is there a way to get only the extensions that match exactly? In the above python files example I would like the following to occur (obviously with the correct syntax substituted for *.py)

C:\CODE\metcal>dir /b *.py
metcal.py

请注意,Windows下的匹配并不像看起来那样简单.

As a note the matching under Windows not as simple as it seems.

*.exe 匹配 foo.exe,foo.exe1,foo.exeabcde ,但 foo.exe.bak

SO上还有其他与长/短文件名相关的类似问题.此处的* .py和* .pyc示例不应引入名称修饰机制.

There are other questions on SO that are similar that are related to long/short file names. The *.py and *.pyc example here should not introduce name mangling machinery.

**我已经在XP和Win7机器上进行了实验,在cmd提示和文件打开对话框中,这种行为是不一致的.这种不一致的行为使我怀疑此问题与某种设置有关.**

**I have experimented on XP and Win7 machines and this behavior is not consistent at the cmd Prompt and file open dialogs. This inconsistant behavior makes me suspect this problem is related to settings of somekind. **

推荐答案

这是因为扩展名上的Windows通配符会同时检查长名和短名,如此答案中所述: https://superuser.com/Questions/238900/winxp-dir-command-3-and-4-char-extensions-same#238930

It's because windows wildcards on extensions check both long and short names as explained in this answer: https://superuser.com/questions/238900/winxp-dir-command-3-and-4-char-extensions-are-the-same#238930

解决方案是禁用8.3名称创建,然后将其剥离到ntfs卷上,这也将提高性能.

Solution there is to disable 8.3 names creation and then striping them on ntfs volumes which will also improve performance.

Microsoft Docs:Fsutil 8dot3name

备注:永久删除8dot3文件名而不修改指向8dot3文件名的注册表项可能会导致应用程序意外故障,包括无法卸载应用程序.建议您先备份目录或卷,然后再尝试删除8dot3文件名.

Remarks: Permanently removing 8dot3 file names and not modifying registry keys that point to the 8dot3 file names may lead to unexpected application failures, including the inability to uninstall an application. It is recommended you first back up your directory or volume before you attempt to remove 8dot3 file names.

这篇关于如何在Windows/命令行/文件打开对话框下匹配确切的文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆