C# - Program to rename files in a folder


C# - Program to rename files in a folder

CODE
using System; using System.IO; class Program { public static void Main(string[] args) { string inputFolder = @"C:\Test\Test"; DirectoryInfo di = new DirectoryInfo(inputFolder); FileInfo[] files = di.GetFiles(); //loop through the files in the folder //delete the file prefixes "IMG-" of the file name. foreach(FileInfo fi in files) { string oldFileName = fi.Name; string newFileName = fi.Name.Replace("IMG-", ""); string newFileFullName = fi.DirectoryName + "\\" + newFileName; fi.MoveTo(newFileFullName); Console.WriteLine("{0} renamed to {1}", oldFileName, newFileName); } Console.ReadKey(); } }

INPUT & OUTPUT
The below is the output of the program.

Comments