Beispiel #1
0
        public Lister(string path, string arg)
        {
            if (arg.Length == 0)
            {
                this.noArgs = true;
            }
            else
            {
                this.arg = arg;
            }
            this.path = path;

            CheckArgs();
            char items = this.items.Count == 1 ? ' ' : 's';

            if (this.items.Count == 0)
            {
                System.Console.WriteLine("No items found in the current directory to display.");
                Internal.Starter(this.path);
            }

            Internal.Ask($"{this.items.Count} item{items} found. Display everything?[y/n]:");
            char yn = System.Console.ReadLine().ToCharArray()[0];

            try
            {
                if (this.items.Count == 0)
                {
                    Internal.Starter(this.path);
                }
                if (yn == 'y' && this.items.Count != 0 && this.items != null)
                {
                    foreach (string item in this.items)
                    {
                        System.Console.WriteLine(item);
                    }
                }
                Internal.Starter(this.path);
            }
            catch (System.ArgumentOutOfRangeException) { Internal.Starter(this.path); }
            catch (System.IndexOutOfRangeException) { Internal.Starter(this.path); }
            catch (System.NullReferenceException) { Internal.Error("No items to display!"); Internal.Starter(this.path); }
        }
Beispiel #2
0
        /// <summary>
        /// Deletes every file with name, matching the <paramref name="matchSign"/> argument.
        /// </summary>
        /// <param name="path">The full path to file to look for.</param>
        /// <param name="matchSign">A sign to look for.</param>
        private void DeleteEverythingWhereMatches(string path, string matchSign)
        {
            if (CheckPath(path))
            {
                if (matchSign != string.Empty || matchSign != " " || matchSign != null)
                {
                    var dirItems = Directory.GetFiles(path);

                    var commonItems = new System.Collections.Generic.List <string>();

                    if (dirItems.Length != 0) //empty directory
                    {
                        foreach (string item in dirItems)
                        {
                            if (Path.GetFileNameWithoutExtension(item) == matchSign)
                            {
                                commonItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        Internal.Error($"The directory {path} is empty!");
                    }

                    if (commonItems.Count == 0)
                    {
                        Internal.Error($"No items with matching sign \"{matchSign}\" were found in {path}!");
                    }
                    // at least 1 common item
                    else
                    {
                        System.Console.WriteLine("MATCHING FILES FOUND!");


                        Internal.Ask($"Show all {commonItems.Count} matching files?[Y/N]:"); char yn = System.Console.ReadLine().ToLower().ToCharArray()[0];

                        if (yn == 'y') //if you want to see all the items
                        {
                            System.Console.WriteLine("FILES TO DELETE:");
                            foreach (string item in commonItems)
                            {
                                System.Console.WriteLine(item);
                            }
                        }

                        Internal.Ask("Are you sure you want to delete all these items?:[Y/N]"); char y = System.Console.ReadLine().ToLower().ToCharArray()[0];

                        if (y == 'y')
                        {
                            foreach (string item in commonItems)
                            {
                                File.Delete(item);
                            }
                        }
                    }
                }
                else
                {
                    Internal.Error("Empty \"matchSign\" argument!");
                }
            }
            else
            {
                Internal.Error("The path is incorrect or does not exist!");
            }

            Internal.Starter(this.path);
        }