Example #1
0
        private static void Extraction(string filePathToExtract)
        {
            bool   iSExtractionSuccessful = false;
            string extractionDir          = Path.GetFileNameWithoutExtension(filePathToExtract);

            try
            {
                Console.WriteLine("Starting unpacking . . .");
                ZipFile.ExtractToDirectory(filePathToExtract, extractionDir);
                Console.WriteLine("Everything should be fine!");
                iSExtractionSuccessful = true;
            }

            catch (Exception)
            {
                PimpMyWriting.ApplyColor(OPERATION_FAILED,
                                         ConsoleColor.Red);
            }

            finally
            {
                if (iSExtractionSuccessful)
                {
                    File.Delete(filePathToExtract);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Displays available zip files in current directory.
        /// Program terminates if no zip files are found.
        /// </summary>
        /// <param name="path"></param>
        private static string[] GetZipFilesInCurrentDirectory(string path)
        {
            var files = Directory.GetFiles(path, "*.zip");

            if (files.Length == 0)
            {
                PimpMyWriting.ApplyColor(NO_FILES_MESSAGE, ConsoleColor.Cyan);
                Console.WriteLine("Press any key to exit...");
                Console.ReadLine();
                Environment.Exit(0);
            }

            for (int i = 0; i < files.Length; i++)
            {
                files[i] = Path.GetFileName(files[i]);
            }
            return(files);
        }
Example #3
0
        static void Main()
        {
            Console.Title = "ZipExtractorApp";
            PimpMyWriting.ApplyColor(CURRENT_PATH, ConsoleColor.Yellow);
            Console.WriteLine();

            var files = GetZipFilesInCurrentDirectory(CURRENT_PATH);

            for (var i = 0; i < files.Length; i++)
            {
                string fileName = files[i];
                string zipDir   = CURRENT_PATH + PATH_SEPARATOR + fileName;

                var startExtraction = DateTime.Now;
                Extraction(zipDir);
                var finishExtraction = DateTime.Now;

                var timePassed = TimePassed(startExtraction, finishExtraction);
                Console.WriteLine($"Time passed: {timePassed}");
            }
            Console.ReadLine();
        }