Ejemplo n.º 1
0
 public static void MoveFile(FileInfo fi, string newPath, int numFile, bool isRenameFile)
 {
     Console.Write("    Moving File: ");
     ColorsLines.WriteLineC(fi.FullName, DarkYellow);
     try {
         //string nameOk = NameAdaptingToNotOvveride(Path.GetFileNameWithoutExtension(fi.Name), Path.Combine(newPath, fi.Name), fi.Extension);
         //nameOk += fi.Extension;
         //File.Move(fi.FullName, Path.Combine(newPath, fileName)); // PathTooLongException move file
         if (isRenameFile)
         {
             Console.Write("   in to "); ColorsLines.WriteC(newPath + '\\', Yellow); ColorsLines.WriteC(numFile.ToString() + fi.Extension, Cyan);
             fi.MoveTo(Path.Combine(newPath, $"{numFile}{fi.Extension}"), false);
         }
         else
         {
             Console.Write("   in to "); ColorsLines.WriteC(newPath + '\\', Yellow); ColorsLines.WriteC(fi.Name, Cyan);
             fi.MoveTo(Path.Combine(newPath, fi.Name), false);
         }
         Console.Write(" ... "); ColorsLines.WriteLineC("Done!\r\n", Green);
     } catch (Exception e) {
         Console.Write(" ... "); ColorsLines.WriteLineC("ERROR: \r\n", Red);
         errorList.Add($"Error with file N:{numFile} - {fi.FullName} MSG:\r\n {e}");
     }
     //return newPath;
 }
Ejemplo n.º 2
0
        public static void CreateFolder(string path, string name)
        {
            try
            {
                // Determine whether the directory exists.
                if (!Directory.Exists(Path.Combine(path, name)))
                {
                    Console.Write("    Creating folder in: "); ColorsLines.WriteLineC(path, DarkYellow);
                    Console.Write("    Name: "); ColorsLines.WriteC(name, Yellow);
                }
                else
                {
                    return;
                }

                // Try to create the directory.
                DirectoryInfo di = Directory.CreateDirectory(Path.Combine(path, name));
                Console.Write(" - "); ColorsLines.WriteC("Done!", Green); Console.Write(" - In the: ");
                ColorsLines.WriteLineC(Directory.GetCreationTime(Path.Combine(path, name)).ToString(), Magenta);

                // Delete the directory.
                //di.Delete();
                //Console.WriteLine("The directory was deleted successfully.");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write($"The process failed: {0}", e); Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            finally { }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
 private static void DelleteEmptyFolder(string startLocation)
 {
     foreach (var directory in Directory.GetDirectories(startLocation))
     {
         DelleteEmptyFolder(directory);
         if (Directory.GetFiles(directory).Length == 0 && Directory.GetDirectories(directory).Length == 0)
         {
             Directory.Delete(directory, false);
             ColorsLines.WriteC("Deleted DIR: ", Red); Console.Write(directory); ColorsLines.WriteLineC(" - Done!", Green);
         }
     }
 }