我在我的应用中使用了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)}
答案 0 :(得分:0)
找不到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(@"\", @"/"));