文件打开的自定义扩展选择文件名中的匹配模式 [英] File open's custom extensions picks up matching pattern in filename

查看:115
本文介绍了文件打开的自定义扩展选择文件名中的匹配模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,



我在WinForms应用程序中使用标准的文件打开对话框,提示用户输入许可证文件(扩展名为.lic )在启动时,如果我在预定义的文件夹中找不到一个。我的搜索过滤器设置为:



string strFilter =许可证文件(* .lic)| * .lic;



我注意到一个小问题:如果文件夹碰巧有所选文件夹中的my.licensemanager.dll,那么因为* .lic匹配是*的一部分filename *(而不是扩展名),它包含在正在显示的文件列表中 - 但在这种情况下是一个DLL,它显然永远不会是一个有效的选择。



我原本以为搜索* .lic就不会拿起这个文件 - 只有* .lic *会把它拿起来,这是我用过的搜索条件 - 但是不,我正在使用* .lic。这就是命令提示符下dir * .lic的行为 - 除非我添加终止*,否则将排除DLL。



我一直在使用几十年的文件打开对话框 - 在.NET之前,在MFC之前,一直回到C中的原始Win32 API甚至......我直到现在才注意到这一点。



我意识到我可以以某种方式扩展文件打开对话框,这样我就可以完全控制包含的内容,但是(a)对我来说似乎有些过分,并且(b)扩展了文件打开对话框似乎总是带着一些警告或无意识的怪癖,这比我想要解决的原始问题更糟糕。



是否有替代搜索模式我可能能够使用 - 也许是我错过的正则表达式选项,而不是纯文本?我记不起在文档中看过这个了。



我尝试了什么:



没有多少替代方法可以尝试 - 我正在遵循文档中的文档,在我看来,这似乎是一个糟糕的实现。

Hey all,

I'm using the standard File Open dialog box in my WinForms app, to prompt the user for a license file (extension ".lic") at startup if I don't find one in a predefined folder. My search filter is set to:

string strFilter = "License files (*.lic)|*.lic";

I've noticed a slight problem: If the folder happens to have, for example, "my.licensemanager.dll" in the selected folder, then because there's a ".lic" match as part of the *filename* (rather than extension), it gets included in the list of files being displayed - but being a DLL in this case, it obviously never will be a valid selection.

I would've thought a search for "*.lic" would NOT have picked up this file - only "*.lic*" would have picked it up, had this been the search criteria I would've used--but no, I'm using "*.lic". This is how "dir *.lic" at a command prompt behaves - the DLL is excluded unless I add the terminating "*".

I've been using the File Open dialog box for decades - pre-.NET, pre-MFC, going all the way back to the raw Win32 API in C even...and I hadn't noticed this until now.

I realize I can probably extend the File Open dialog in some fashion so I get full control over what gets included, but that (a) seems like overkill to me and (b) extending the File Open dialog always seems to carry with it some caveats or unintended quirk that's worse than the original problem I'm trying to solve.

Is there an alternate search pattern I might be able to use--a regex option perhaps that I've missed, instead of plain-text? I don't recall ever seen this in the documentation.

What I have tried:

Not many alternatives to try - I'm following the documentation to the letter and it seems to me like a bad implementation.

推荐答案

当我试试这个:

When I try that:
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "License files (*.lic)|*.lic";
if (ofd.ShowDialog() == DialogResult.OK)
    {
    string path = ofd.FileName;
    }

只有文件夹dimchain.lic和DMLog.licence.txt中的两个文件,我可以看到文件列表中的第一个,但不是第二个。如果我输入'd',我可以看到 - 并选择 - 弹出列表中的两个文件,但我根本看不到文件列表中的DMLog.licence.txt。



我和你做什么不同?

With just two files in the folder "dimchain.lic" and "DMLog.licence.txt" i can see the first, but not the second in the files list. If I type 'd' I can see - and select - both files in the pop-out list, but I cannot see "DMLog.licence.txt" in teh files list at all.

What am I doing differently from you?


好问题。我在干净的Windows 8和8.1 VM上看过这个。在这两种情况下,Windows资源管理器都设置为显示所有内容(根本不隐藏任何内容)。
Good question. I've seen this on clean Windows 8 and 8.1 VMs. In both instances, Windows Explorer is set to show everything (don't hide anything at all--ever).


这篇关于文件打开的自定义扩展选择文件名中的匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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