我有从Unity项目存储文件的项目。我想要的是找到这些文件并压缩它们。我想用ZipFile Class。我的代码很简单如下:表达式表示`方法组“其中一个`变量”,`值“或'类型”预计
string dataSource = @"D:\\dt\\2015-11-09-11\\";
string zipFile = @"D:\\dt\\2015-11-09-11\\file.zip";
ZipFile.CreateFromDirectory(dataSource, zipFile, CompressionLevel.Fastest, true);
不过我正在从团结的错误:
Assets/file.cs(54,25): error CS0119: Expression denotes a
method group', where a
variable',value' or
type' was expected
我在做什么错在这里?
编辑:THS的问题是使用ZipFile类是.NET 4.5和更高而团结是.NET 3.5。我按照以下lib中的建议更改我使用的库。我现在的代码是这样的:
string dataSource = @"D:\\data\\2015-11-09-11-11-37-3286";
FileStream fsOut = File.Create(dataSource);
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel(3);
int folderOffset = dataSource.Length + (dataSource.EndsWith("\\") ? 0 : 1);
CompressFolder(dataSource, zipStream, folderOffset);
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close();
CompressFolder方法可以找到here。我收到以下消息(该目录是一个现有路径):
DirectoryNotFoundException: Could not find a part of the path "D:\data\2015-11-09-11-11-37-3286". System.IO.FileStream..ctor
问题是位于建议代码FileStream out = File.Create(dataSource);
'ZipFile'可从.NET 4.5开始......团结就是落后的方式,据我所知。现在相当你为什么得到*确切的*错误信息很难说没有更多的上下文。我的猜测是你也有一个名为'ZipFile'的方法。很高兴知道file.cs第54行第25行的内容...... –
是的,您正确的是第三行CreateFromDirectory。我认为这种情况是.NET冲突,因为统一只支持3.5。 ZipFile for UNity的其他选择吗? –
您可能需要改用SharpZipLib。 –