2015-11-09 37 views
0

我有從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);

+0

'ZipFile'可從.NET 4.5開始......團結就是落後的方式,據我所知。現在相當你爲什麼得到*確切的*錯誤信息很難說沒有更多的上下文。我的猜測是你也有一個名爲'ZipFile'的方法。很高興知道file.cs第54行第25行的內容...... –

+0

是的,您正確的是第三行CreateFromDirectory。我認爲這種情況是.NET衝突,因爲統一隻支持3.5。 ZipFile for UNity的其他選擇嗎? –

+0

您可能需要改用SharpZipLib。 –

回答

1

上肢體的第二行,我建議你呼籲方法ZipFile也是如此。

其重命名爲東西,不與類名衝突或使用Using alias = ...聲明。

0

我想我得到了它。 Unity瀏覽未知目錄時遇到問題。當我將目錄更改爲一個文件夾時,Unity已經可以訪問一切正常。

相關問題