Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Text;
- namespace RenameMusicFiles
- {
- class RenameMusicFiles
- {
- static void Main()
- {
- Console.WriteLine("Directory path:");
- string dir = Console.ReadLine();
- Console.WriteLine("Characters to remove from the front:");
- int cut = int.Parse(Console.ReadLine());
- string[] oldNames = Directory.GetFiles(dir);
- string[] newNames = new string[oldNames.Length];
- string newName;
- for (int i = 0; i < oldNames.Length; i++)
- {
- newName = Fix(oldNames[i].Substring(dir.Length + 1 + cut));
- newNames[i] = String.Concat(dir, "\\", newName);
- }
- for (int i = 0; i < oldNames.Length; i++)
- {
- File.Copy(oldNames[i], newNames[i]);
- File.Delete(oldNames[i]);
- }
- Console.WriteLine("Done");
- }
- private static string Fix(string p)
- {
- StringBuilder sb = new StringBuilder();
- foreach (var item in p)
- {
- if (item != '_')
- {
- sb.Append(item);
- }
- else
- sb.Append(' ');
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement