Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                core.PrintAppInfoOnConsole();

                if (args != null && args.Length == 1 && args[0] != null)
                {
                    Console.WriteLine("Folder  it's working under : \n{0}", args[0]);
                    core.Rename(args[0]);
                }
                else
                {
                    Console.WriteLine("Use it {0} +  folder Path from command line \n ", Application.ExecutablePath);
                }
                Console.WriteLine("Finishded at: " + DateTime.Now.ToLongDateString() + "\n" + DateTime.Now.ToLongTimeString() + "\n Press Enter to Exit\n");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                RenameLogger.errorhandling(ex);
                Console.ReadLine();
                //MessageBox.Show(ex.ToString());
                // Scrabler.ScrablerCore.ErrorLogScript(ex);
            }
        }
Esempio n. 2
0
        public void PrintAppInfoOnConsole()
        {
            try
            {
                String AppInfo, desc;
                desc    = "A small console utility which renames files with their md5 hash as their name";
                AppInfo = String.Format("{0}  {1} \n {2} \n {3} \n", Application.ProductName, Application.ProductVersion, Application.CompanyName, desc);

                Console.WriteLine(AppInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                RenameLogger.errorhandling(ex);
            }
        }
Esempio n. 3
0
        public Boolean CheckIfFileExists(string filename)
        {
            try
            {
                Boolean ap = false;



                return(File.Exists(filename));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                RenameLogger.errorhandling(ex);
                return(false);
            }
        }
Esempio n. 4
0
        public void CheckIfDirecotryExistOrCreateit(string directory)
        {
            try
            {
                bool ap = false;

                if (Directory.Exists(directory) == false)
                {
                    Directory.CreateDirectory(directory);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                RenameLogger.errorhandling(ex);
            }
        }
Esempio n. 5
0
 public void Rename(string path)
 {
     try
     {
         if (path != null)
         {
             string filesdidnotcopied = "";
             foreach (string s in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
             {
                 string t = Path.GetFileName(s);
                 if (t.StartsWith("."))
                 {
                     int    i;
                     string d = t.Substring(1);
                     string e = Path.GetDirectoryName(s);
                     File.Move(s, Path.Combine(e, d));
                 }
                 if (t.Contains(" ") == true || t.Contains("image") == true || t.Contains("image ") == true)
                 {
                     StringBuilder sBuilder = new StringBuilder();
                     using (var md5 = MD5.Create())
                     {
                         using (var stream = File.OpenRead(s))
                         {
                             var data = md5.ComputeHash(stream);
                             for (int i = 0; i < data.Length; i++)
                             {
                                 sBuilder.Append(data[i].ToString("x2"));
                                 // sBuilder.Append(data[i].ToString());
                             }
                             Console.WriteLine("Renaming the file : {0}", t);
                             string filename = sBuilder.ToString();
                             string ext      = Path.GetExtension(s);
                             string e        = Path.GetDirectoryName(s);
                             this.CheckIfDirecotryExistOrCreateit(Path.Combine(e, diroffolderthatfilesexit));
                             string newfilename = Path.Combine(e, filename) + ext;
                             stream.Close();
                             if (this.CheckIfFileExists(newfilename) == false)
                             {
                                 File.Move(s, newfilename);
                                 string msg = "File  renamed succesfully  From " + s + " To " + newfilename;
                                 RenameLogger.LogMessage(msg);
                             }
                             else
                             {
                                 filesdidnotcopied += "\n" + s;
                                 string msg = "File " + s + " already exists in  " + path + " so it is moved to "
                                              + Path.Combine(e, diroffolderthatfilesexit) + "\\" + Path.GetFileName(s);
                                 File.Move(s, Path.Combine(e, diroffolderthatfilesexit) + "\\" + Path.GetFileName(s));
                                 RenameLogger.LogMessage(msg);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         RenameLogger.errorhandling(ex);
     }
 }