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


C# ZipFile.UpdateDirectory方法代码示例

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


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

示例1: Archivage

        public int Archivage()
        {
            int intCodeRetour = 0x00; //=== Code de retour Normalement Terminer

            //==== Periode selon la date du jour par défaut
            string strSQL = "SELECT cp.cal_no_emission FROM lg2_calen_prod cp WHERE cp.cal_dt_emission <= ADD_MONTHS(SYSDATE, :Mois_A_Conserver) ORDER BY cp.cal_dt_emission DESC";

            OracleConnection objConn = new OracleConnection(Properties.Settings.Default.CONNECTSTRING); ;
            OracleCommand objCmd = new OracleCommand(strSQL, objConn);
            OracleDataReader odr = null;

            // create a writer and open the file
            TextWriter log = new StreamWriter(".\\logs\\DV1L3001_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".log");

            try
            {

                // write a line of text to the file
                log.WriteLine(DateTime.Now.ToString() + "==== DEBUT DU TRAITEMENT");
                log.WriteLine(DateTime.Now + " _sourceFolder = " + _sourceFolder);
                log.WriteLine(DateTime.Now + " _backupFolder = " + _backupFolder);
                log.WriteLine(DateTime.Now + " _nbMoisAConserver = " + _nbMoisAConserver);

                #region Validation des informations
                string msgErreur = "";
                //=== On vérifie si répertoire de destination existe
                if (!Directory.Exists(_sourceFolder))
                {
                    msgErreur += "Le répertoire source est inexistant. [source_folder = " + _sourceFolder + "]<BR>";
                }
                if (!Directory.Exists(_backupFolder))
                {
                    msgErreur += "Le répertoire de sauvegarde est inexistant à l'endroit spécifié. [backup_destination_folder = " + _backupFolder + "]<BR>";
                }

                if (msgErreur != "")
                {
                    log.WriteLine(DateTime.Now + " ERROR : " + msgErreur.ToString());
                    throw new ApplicationException(msgErreur);
                }
                #endregion

                objConn.Open();
                //==== On soustrait les mois pour trouver la date de départ
                objCmd.Parameters.Add("Mois_A_Conserver", OracleDbType.Varchar2).Value = _nbMoisAConserver * -1;

                odr = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

                long noEmission = 0;
                if (odr.Read())
                {
                    noEmission = _noEmissionBase + (int)odr["cal_no_emission"];
                    log.WriteLine(DateTime.Now + " Start with noEmission = " + noEmission.ToString());
                }
                else
                {
                    log.WriteLine(DateTime.Now + " Start with noEmission = AUCUNE ÉMISSION");
                }

                int nbMissingFolders = 0;
                for (long i = noEmission; i >= _noEmissionBase; i--)
                {
                    //=== Si le folder existe on le zip
                    string archiveFolder = _sourceFolder + "\\" + i.ToString();

                    if (Directory.Exists(archiveFolder))
                    {
                        nbMissingFolders = 0;
                        log.WriteLine(DateTime.Now + " FOLDER EXIST archiveFolder = " + archiveFolder.ToString());
                        using (ZipFile zip = new ZipFile())
                        {
                            zip.UpdateDirectory(archiveFolder);//==== Répertoire qui sera compressé
                            zip.Save(_backupFolder + "\\" + i.ToString() + ".zip");  //=== Nom et emplacement du fichier ZIP
                            log.WriteLine(DateTime.Now + " ZIP TO : " + _backupFolder + "\\" + i.ToString() + ".zip");
                            zip.Dispose();
                        }
                        Directory.Delete(archiveFolder, true); //==== Supprime le répertoire qui a été compressé
                        log.WriteLine(DateTime.Now + " DELETE UNCOMPRESSED FOLDER : " + archiveFolder.ToString());
                    }
                    else
                    {
                        nbMissingFolders++; //=== Cumule le nombre de répertoire manquan
                        log.WriteLine(DateTime.Now + " _" + nbMissingFolders + "_ FOLDER DOESNT EXIST archiveFolder = " + archiveFolder.ToString());

                        if (nbMissingFolders >= _maxNbMissingFolder)//=== Si 5 répertoire consécutif n'existe pas on arrete le traitement.
                        {
                            log.WriteLine(DateTime.Now + " STOP CAUSE BY MORE THEN " + _maxNbMissingFolder.ToString() + " MISSING FOLDERS");
                            break;
                        }

                    }
                }

                log.WriteLine(DateTime.Now.ToString() + "==== FIN DU TRAITEMENT");

            }
            catch (Exception ex)
            {
                //=== Envoie de courriel sur erreur
                intCodeRetour = _codeRetourErreur;
//.........这里部分代码省略.........
开发者ID:judgeprophet,项目名称:DV1L3001_ArchivageFichiersRdi,代码行数:101,代码来源:ArchivageRDI.cs


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