正在搜索名为 "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
}
我怎样才能select这些文件?
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(@"\", @"/"));
我在我的应用程序中使用 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
}
我怎样才能select这些文件?
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(@"\", @"/"));