Search This Blog

Wednesday, March 23, 2016

Rename files from a folder C#

C# > Files > File Class > Move


Moves a specified file to a new location.
  • option to specify a new file name

Example 

Rename files from a folder 

DirectoryInfo d = new DirectoryInfo(@"D:\folder");
FileInfo[] infos = d.GetFiles("*.*");
int i = 1;
foreach (FileInfo f in infos)
{
  File.Move(f.FullName, Path.Combine(f.DirectoryName, + i.ToString() + ".jpg"));
  i++;
}