繁体   English   中英

搜索名为“ test(').txt”的文件

[英]Searching for a file named “test (').txt”

我在我的应用程序中使用dotnetzip,并且收到了有关包含'('和')'文件的崩溃的问题报告

            using (ZipFile zip = new ZipFile("test.zip"))
            {
                var e = zip.SelectEntries("test (').txt"); //System.ArgumentException
                e = zip.SelectEntries("name = test (').txt"); //System.ArgumentException
                e = zip.SelectEntries("(name = test (').txt)"); //System.ArgumentException

                e = zip.SelectEntries( "'test ()'" ); // OK
                e = zip.SelectEntries( "'test (')'" ); //System.ArgumentException
                e = zip.SelectEntries( "test ()" ); //System.ArgumentException
            }

如何选择这些文件?

zip.SelectEntries( "name = test (').txt)" )
'zip.SelectEntries( "name = test (').txt)" )' threw an exception of type 'System.ArgumentException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
InnerException: null
Message: "'name\u0006=\u0006test\u0006(''"
ParamName: null
Source: "Ionic.Zip"
StackTrace: "   at Ionic.FileSelector._ParseCriterion(String s)\r\n   at Ionic.FileSelector..ctor(String selectionCriteria, Boolean traverseDirectoryReparsePoints)\r\n   at Ionic.Zip.ZipFile.SelectEntries(String selectionCriteria)"
TargetSite: {Ionic.SelectionCriterion _ParseCriterion(System.String)}

使用SelectEntries找不到解决方案。

正如Lasse V. Karlsen所建议的那样,我在zip库之外进行搜索。 由于我只查找单个文件,因此很简单:

var e = zip.Entries.FirstOrDefault(s => s.FileName == "test (').txt");

请注意,如果zip中有子文件夹,则必须将反斜杠转换为斜杠:

string name=@"(=')\test (').txt"
var e = zip.Entries.FirstOrDefault(s => s.FileName == name.Key.Replace(@"\", @"/"));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM