Hej,
sådan lige et hurtigt forslag til inspiration..
- class Program
- {
- private const string inputDir = @"C:\rename";
- private const string outputDir = @"C:\rename\renamed\";
- private const string prefix = "Anmeldelse ";
- static void Main(string[] args)
- {
- string[] fileNames = Directory.GetFiles(inputDir, "*.txt");
- string pattern = @"\b\d{4}\b";
- System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pattern);
-
- foreach(var fileName in fileNames)
- {
- string shortFileName = Path.GetFileNameWithoutExtension(fileName).Replace("_", " ").Replace(".", " ");
- string newFileName = "";
- if (r.Matches(shortFileName).Count > 0 && Convert.ToInt16(r.Match(shortFileName).Value) > 1900 && Convert.ToInt16(r.Match(shortFileName).Value) < 2016)
- newFileName = prefix +shortFileName.Replace(r.Match(shortFileName).ToString(), "") + " (" + r.Match(shortFileName) + ").ext";
- else
- newFileName = prefix + shortFileName + ".ext";
- if (!File.Exists(outputDir + newFileName))
- File.Copy(fileName, outputDir + newFileName);
- }
- Console.WriteLine("Slut prut");
- }
- }
Indlæg senest redigeret d. 11.11.2014 22:55 af Bruger #10576