Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            bool isRenameFile = false;

            Console.WriteLine("  ---        <-_ Welcome Corgdirile by Arutosio_->        ---  ");
            Console.Write("  ~  "); ColorsLines.WriteC("For more info: https://github.com/Arutosio/Corgdirile", Cyan); Console.WriteLine("  ~  ");
            do
            {
                errorList = new ArrayList();
                Console.WriteLine();
                //Fase Preparing..
                LineFase("Setup");
                string pathSource      = SetDirectory("Write the files path: ");
                string pathDestination = SetDirectory("Write the destination path: ");
                Console.Write("Press the "); ColorsLines.WriteC("Y", Green); Console.Write(" Do you want rename files with the num count? "); ColorsLines.WriteC("exit", Red); Console.Write(": ");
                isRenameFile = Console.ReadKey().KeyChar.ToString().ToLower().Equals("y");
                ChooseOrder();
                //string[] allfiles = Directory.GetFileSystemEntries(pathSource);
                // Fase Processing..
                LineFase("Processing");
                string[]   allfiles     = Directory.GetFiles(pathSource, "*", SearchOption.AllDirectories);
                FileInfo[] allFileInfos = new FileInfo[allfiles.Length];
                for (uint i = 0; i < allfiles.Length; i++)
                {
                    allFileInfos[i] = new FileInfo(allfiles[i]);
                }

                for (int i = 0; i < allFileInfos.Length; i++)
                {
                    DateTime fileDate  = OrderBy(allFileInfos[i]);
                    string   yearFile  = fileDate.Year.ToString();
                    string   monthFile = fileDate.Month.ToString();
                    Console.Write($"File Num: {i+1} - Name: "); ColorsLines.WriteLineC(allFileInfos[i].Name, Cyan);
                    CreateFolder(pathDestination, yearFile);
                    CreateFolder(Path.Combine(pathDestination, yearFile), yearFile + "-" + monthFile);
                    string fullPath = Path.Combine(pathDestination, yearFile, $"{yearFile}-{monthFile}");

                    MoveFile(allFileInfos[i], fullPath, i + 1, isRenameFile); // PathTooLongException move file
                }
                Console.Write("Do you wont to delete all empy folders?");
                if (ColorsLines.Ask())
                {
                    DelleteEmptyFolder(pathSource);
                }
                PrintErrors();
                Console.Write("\r\n======> "); ColorsLines.WriteC("PROCESS FINISH!", Green); Console.WriteLine(" <======");
                Console.Write("Press the "); ColorsLines.WriteC("Y", Green); Console.Write(" key to execute again the program or press an other key to "); ColorsLines.WriteC("exit", Red); Console.Write(": ");
            }while(Console.ReadKey().KeyChar.ToString().ToLower().Equals("y"));
            Console.WriteLine();
        }