当前位置: 首页>>代码示例>>C#>>正文


C# ZipFile.AddDirectory方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.AddDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.AddDirectory方法的具体用法?C# ZipFile.AddDirectory怎么用?C# ZipFile.AddDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.AddDirectory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFilesToZip

 /// <summary>
 /// Iterate thru all the filesysteminfo objects and add it to our zip file
 /// </summary>
 /// <param name="fileSystemInfosToZip">a collection of files/directores</param>
 /// <param name="z">our existing ZipFile object</param>
 private static void GetFilesToZip(FileSystemInfo[] fileSystemInfosToZip, ZipFile z)
 {
     //check whether the objects are null
     if (fileSystemInfosToZip != null && z != null)
     {
         //iterate thru all the filesystem info objects
         foreach (FileSystemInfo fi in fileSystemInfosToZip)
         {
             //check if it is a directory
             if (fi is DirectoryInfo)
             {
                 DirectoryInfo di = (DirectoryInfo)fi;
                 //add the directory
                 z.AddDirectory(di.FullName);
                 //drill thru the directory to get all
                 //the files and folders inside it.
                 GetFilesToZip(di.GetFileSystemInfos(), z);
             }
             else
             {
                 //add it
                 z.Add(fi.FullName);
             }
         }
     }
 }
开发者ID:dtafe,项目名称:vnr,代码行数:31,代码来源:SharpZipLibExtensions.cs

示例2: CompressDataInToFile

        public void CompressDataInToFile(string directory, string password, string outputFile)
        {
            var fullFileListing = Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories);
            var directories = Directory.EnumerateDirectories(directory, "*", SearchOption.AllDirectories);

            _logger.Information("Creating ZIP File");
            using (var zip = new ZipFile(outputFile))
            {
                zip.UseZip64 = UseZip64.On;

                _logger.Information("Adding directories..");
                foreach (var childDirectory in directories)
                {
                    _logger.Information(string.Format("Adding {0}", childDirectory.Replace(directory, string.Empty)));
                    zip.BeginUpdate();
                    zip.AddDirectory(childDirectory.Replace(directory, string.Empty));
                    zip.CommitUpdate();
                }

                _logger.Information("Adding files..");
                foreach (var file in fullFileListing)
                {
                    _logger.Information(string.Format("Adding {0}", file.Replace(directory, string.Empty)));
                    zip.BeginUpdate();
                    zip.Add(file, file.Replace(directory, string.Empty));
                    zip.CommitUpdate();
                }

                _logger.Information("Setting password..");
                zip.BeginUpdate();
                zip.Password = password;
                zip.CommitUpdate();
            }
        }
开发者ID:tombuildsstuff,项目名称:SimpleBackup,代码行数:34,代码来源:ZipCompressData.cs

示例3: SetContent

        void SetContent(string loc, byte[] content)
        {
            ZipFile zipFile = new ZipFile(FileLoc);

            // Must call BeginUpdate to start, and CommitUpdate at the end.
            zipFile.BeginUpdate();
            if (loc.Contains('/'))
            {
                int i = loc.IndexOf('/');
                string dir = loc.Remove(i + 1, loc.Length - i - 1);
                if (zipFile.FindEntry(dir, true) < 0)
                {
                    zipFile.AddDirectory(dir);
                }
            }
            CustomStaticDataSource sds = new CustomStaticDataSource();
            using (MemoryStream ms = new MemoryStream(content))
            {
                sds.SetStream(ms);

                // If an entry of the same name already exists, it will be overwritten; otherwise added.
                zipFile.Add(sds, loc);

                // Both CommitUpdate and Close must be called.
                zipFile.CommitUpdate();
                zipFile.Close();
            }
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:28,代码来源:ZipStorage.cs

示例4: AddDirectory

        void AddDirectory(string loc)
        {
            ZipFile zipFile = new ZipFile(FileLoc);

            // Must call BeginUpdate to start, and CommitUpdate at the end.
            zipFile.BeginUpdate();
            zipFile.AddDirectory(loc);
            // Both CommitUpdate and Close must be called.
            zipFile.CommitUpdate();
            zipFile.Close();
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:11,代码来源:ZipStorage.cs

示例5: AddDirectory

        void AddDirectory(string loc)
        {
            ZipFile zipFile = new ZipFile(this.zipArchive);

            // Must call BeginUpdate to start, and CommitUpdate at the end.
            zipFile.BeginUpdate();
            zipFile.AddDirectory(loc);
            // Both CommitUpdate and Close must be called.
            zipFile.CommitUpdate();
            zipFile.IsStreamOwner = false; zipFile.Close();

            this.zipArchive.Position = 0;
        }
开发者ID:alejandraa,项目名称:TaskMQ,代码行数:13,代码来源:ZipStream.cs

示例6: AddDirectoryFilesToZip

        /// <summary>
        /// Recursively adds folders and files to archive
        /// </summary>
        /// <param name="root">The root directory.</param>
        /// <param name="zipArchive"></param>
        /// <param name="sourceDirectory"></param>
        /// <param name="recurse"></param>
        private static void AddDirectoryFilesToZip(string root,ZipFile zipArchive, string sourceDirectory, bool recurse)
        {
            // Add this directory
            zipArchive.AddDirectory(root + "/" + sourceDirectory);

            // Recursively add sub-folders
            if (recurse)
            {
                string[] directories = Directory.GetDirectories(sourceDirectory);
                foreach (string directory in directories)
                {
                    AddDirectoryFilesToZip(root,zipArchive, directory, recurse);
                }
            }

            // Add files
            string[] filenames = Directory.GetFiles(sourceDirectory);
            foreach (string filename in filenames)
            {
                string name = filename;

                if (name.StartsWith(@".\"))
                {
                    name = name.Substring(2, name.Length - 2);
                }

                if (!String.IsNullOrEmpty(root))
                {
                    name = root + @"\" + name;
                }

                Console.WriteLine("{0} -> {1}", filename, name);

                zipArchive.Add(filename, name);

            }
        }
开发者ID:ThumbWhere,项目名称:ThumbWhere-Drupal7-Module,代码行数:44,代码来源:Program.cs

示例7: GenerateImage

        /// <summary>
        /// Generates the image.
        /// </summary>
        /// <remarks>CFI, 2012-02-24</remarks>
        private void GenerateImage()
        {
            #region Check parameter:

            if (!Directory.Exists(textBoxInputFilePath.Text))
                throw new DirectoryNotFoundException("The input directory was not found!");
            if (!Directory.Exists(Path.GetDirectoryName(textBoxOutputFile.Text)))
                throw new DirectoryNotFoundException("The output path is invalid!");
            if (textBoxStickName.Text.Length > 11 || textBoxStickName.Text == string.Empty)
                throw new ArgumentException("Invalid Stick name!");
            if (textBoxStickID.Text.Length != 9 || textBoxStickID.Text[4] != '-')
                throw new ArgumentException("Invalid Stick ID!");

            #endregion

            string outputFilePath = Path.ChangeExtension(textBoxOutputFile.Text, ".MLifterStick");

            #region Create Zip:

            Stream output = File.Create(outputFilePath);
            ZipOutputStream zipStream = new ZipOutputStream(output);
            ZipFile zip = new ZipFile(output);

            #endregion

            #region Fill Zip:

            zip.BeginUpdate();

            int pos = 1;
            string[] files = Directory.GetFiles(textBoxInputFilePath.Text, "*.*", SearchOption.AllDirectories);
            List<string> folders = new List<string>();
            foreach (string file in files)
            {
                toolStripStatusLabelMessage.Text = string.Format("Adding file {0} of {1}...", pos, files.Length);
                toolStripProgressBarStatus.Value = Convert.ToInt32(pos++ * 1.0 / files.Length * 100);
                Application.DoEvents();

                string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length);
                string zipFile = Path.Combine(dir, Path.GetFileName(file));

                if (dir.Length > 0)
                {
                    if (!folders.Contains(dir))
                    {
                        zip.AddDirectory(dir);
                        folders.Add(dir);
                    }
                }
                zip.Add(new FileDataSource(file), zipFile);
            }

            toolStripStatusLabelMessage.Text = "Saving image. THIS COULD RUN VERY LONG - PLEASE WAIT!";
            Application.DoEvents();

            zip.CommitUpdate();

            #endregion

            VolumeDataStorage vds = new VolumeDataStorage();

            #region setting file attributes:

            foreach (string file in files)
            {
                string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length);
                if (dir.StartsWith("\\"))
                    dir = dir.Remove(0, 1);
                string zipFile = Path.Combine(dir, Path.GetFileName(file)).Replace(@"\", "/");
                ZipEntry entry = zip.GetEntry(zipFile);
                if (entry == null)
                    continue;
                FileAttributes attr = (new FileInfo(file)).Attributes;
                if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal))
                    vds.FileAttributeList.Add(entry.Name, attr);
                toolStripStatusLabelMessage.Text = "Setting file FileAttributes to: " + zipFile;
            }
            foreach (string folder in folders)
            {
                FileAttributes attr = (new DirectoryInfo(Path.Combine(textBoxInputFilePath.Text, folder))).Attributes;
                if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal || attr == FileAttributes.Directory))
                    vds.FolderAttributeList.Add(folder, attr);
                toolStripStatusLabelMessage.Text = "Setting folder FileAttributes to: " + folder;
            }

            #endregion

            #region Set Comment:

            vds.VolumeLabel = textBoxStickName.Text;
            vds.VolumeSerial = textBoxStickID.Text;
            string comment = VolumeDataStorage.SerializeData(vds);

            File.WriteAllText(Path.Combine(Application.StartupPath, "Comment.txt"), comment);

            zip.BeginUpdate();
//.........这里部分代码省略.........
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:101,代码来源:ImageCreatorForm.cs


注:本文中的ICSharpCode.SharpZipLib.Zip.ZipFile.AddDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。