예제 #1
0
        public static bool ExtractTo(string _archiveFile, string _targetDir)
        {
            if (!string.IsNullOrEmpty(_archiveFile) && File.Exists(_archiveFile))
            {
                if (!Directory.Exists(_targetDir))
                {
                    FileFolder.CreateFolder(_targetDir);
                }

                ZipFile.ExtractToDirectory(_archiveFile, _targetDir);

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public static void PreserveLatest(string _targetDir, int _maxCycle)
        {
            if (!string.IsNullOrEmpty(_targetDir))
            {
                List <string> listFiles = new List <string>();

                foreach (string _f in Directory.GetFiles(_targetDir))
                {
                    listFiles.Add(_f);
                }

                if (listFiles.Count > _maxCycle)
                {
                    listFiles.Sort();
                    listFiles.Reverse();

                    for (int x = listFiles.Count; x > _maxCycle; x--)
                    {
                        int y = x - 1;
                        FileFolder.DeleteFile(listFiles[y]);
                        Console.WriteLine(
                            Log.GetTimestamp()
                            + "Deleted: "
                            + listFiles[y]
                            );
                    }
                }
            }
            else
            {
                Console.WriteLine(
                    Log.GetTimestamp()
                    + "Cleanup Error! Make sure target is exist!"
                    );
            }
        }