0
기존 파일을 대체하는 zip 파일에 문제가 있습니다. 나는 여기에 다른 예제를 보았고 나는 그것을 알아낼 수없는 것 같습니다 ... loop
나는 텍스트 상자에 압축을 푼 파일의 일부 통계를 씁니다. 나는 그것이 줄 생각 :파일을 압축 해제하지 않음
if (!System.IO.File.Exists(fileUnzipFullName))
내 코드 :
public void UnzipFileNew()
{
richTextBox1.AppendText("\r\n" + "EXTRACTING!");
String rootpath = Environment.CurrentDirectory;
//This stores the path where the file should be unzipped to,
//including any subfolders that the file was originally in.
string fileUnzipFullPath;
//This is the full name of the destination file including
//the path
string fileUnzipFullName;
//Opens the zip file up to be read
using (ZipArchive archive = ZipFile.OpenRead(@"update.zip"))
{
//Loops through each file in the zip file
foreach (ZipArchiveEntry file in archive.Entries)
{
//Outputs file information to the Textbox
richTextBox1.AppendText("\r\n");
richTextBox1.AppendText("File Name: "+ file.Name);
richTextBox1.AppendText("\r\n");
richTextBox1.AppendText("File Size: bytes "+ file.Length);
richTextBox1.AppendText("\r\n");
richTextBox1.AppendText("Compression Ratio: "+ ((double)file.CompressedLength/file.Length).ToString("0.0%"));
richTextBox1.AppendText("\r\n");
//Identifies the destination file name and path
fileUnzipFullName = Path.Combine(rootpath, file.FullName); //fileUnzipFullName = Path.Combine(@"Example\", file.FullName);
//Extracts
if (!System.IO.File.Exists(fileUnzipFullName))
{
fileUnzipFullPath = Path.GetDirectoryName(fileUnzipFullName);
//Creates the directory if it doesn't exist
Directory.CreateDirectory(fileUnzipFullPath);
//Extracts the file to (potentially new) path
file.ExtractToFile(fileUnzipFullName);
}
}
}
}
존 감사합니다! 이것은 효과가 있었다! zip에 폴더를 추가하여 루트 디렉토리에있는 폴더의 다른 파일을 대체했습니다. 'System.IO.DirectoryNotFoundException : 'C : \ Users \ stump \ source \ repos \ UpdaterTest \ UpdaterTest \ bin \ Debug \ resources \ test \'경로의 일부를 찾을 수 없습니다. '그것은 같은'file.ExtractToFile (fileUnzipFullName, true);에 던져진다. – javajoejuan
오, 나는 실제 _filename_이 필요하다고 생각한다. IIRC'GetDirectoryName'는 디렉토리 만 제공합니다. 그 줄을 주석 처리하면 제대로 작동한다고 생각합니다. – john
답장을 보내 주셔서 다시 한 번 감사드립니다! 하지만 그 라인을 주석 처리 할 때 오류가있는 것 같았습니다. 나는 또한'GetDirectoryName'과 관련된 다른 줄을 시도했다. – javajoejuan