123456789101112131415161718192021222324252627282930 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO.Compression;
- using System.IO;
- using System;
- public class ZipFileController
- {
- // Start is called before the first frame update
- public static void ZipFile(string inputFile, string outputFile)
- {
- // 要压缩的文件路径
- string fileToZip = inputFile;
- // 压缩后的 ZIP 文件路径
- string zipFilePath = outputFile;
- // 创建一个新的 ZIP 文件并将文件添加到其中
- using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Create))
- {
- using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
- {
- // 获取文件名
- string fileName = Path.GetFileName(fileToZip);
- // 将文件添加到 ZIP 文件中
- archive.CreateEntryFromFile(fileToZip, fileName);
- }
- }
- Console.WriteLine("文件已成功压缩到: " + zipFilePath);
- }
- }
|