Advertisement
Guest User

Untitled

a guest
Jun 15th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. namespace RenameMusicFiles
  8. {
  9.     class RenameMusicFiles
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.WriteLine("Directory path:");
  14.             string dir = Console.ReadLine();
  15.  
  16.             Console.WriteLine("Characters to remove from the front:");
  17.             int cut = int.Parse(Console.ReadLine());
  18.  
  19.             string[] oldNames = Directory.GetFiles(dir);
  20.             string[] newNames = new string[oldNames.Length];
  21.             string newName;
  22.  
  23.             for (int i = 0; i < oldNames.Length; i++)
  24.             {
  25.                 newName = Fix(oldNames[i].Substring(dir.Length + 1 + cut));
  26.                 newNames[i] = String.Concat(dir, "\\", newName);
  27.             }
  28.  
  29.             for (int i = 0; i < oldNames.Length; i++)
  30.             {
  31.                 File.Copy(oldNames[i], newNames[i]);
  32.                 File.Delete(oldNames[i]);
  33.             }
  34.  
  35.             Console.WriteLine("Done");
  36.         }
  37.  
  38.         private static string Fix(string p)
  39.         {
  40.             StringBuilder sb = new StringBuilder();
  41.             foreach (var item in p)
  42.             {
  43.                 if (item != '_')
  44.                 {
  45.                     sb.Append(item);
  46.                 }
  47.                 else
  48.                     sb.Append(' ');
  49.             }
  50.             return sb.ToString();
  51.         }
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement