SharpLibZip: Add file without path

前端 未结 3 1067
时光说笑
时光说笑 2021-02-19 02:57

I\'m using the following code, using the SharpZipLib library, to add files to a .zip file, but each file is being stored with its full path. I need to only store the file, in t

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 03:18

    How about using System.IO.Path.GetFileName() combined with the entryName parameter of ZipFile.Add()?

    string[] files = Directory.GetFiles(folderPath);
    using (ZipFile zipFile = ZipFile.Create(zipFilePath))
    {
         zipFile.BeginUpdate();
         foreach (string file in files)
         {
              zipFile.Add(file, System.IO.Path.GetFileName(file));
         }
         zipFile.CommitUpdate();
    }
    

提交回复
热议问题