Skip to content

Instantly share code, notes, and snippets.

@abhaydhar
Created March 5, 2018 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhaydhar/ad1ab0447681de279722c9a419063f73 to your computer and use it in GitHub Desktop.
Save abhaydhar/ad1ab0447681de279722c9a419063f73 to your computer and use it in GitHub Desktop.
Extension Method to Rename a file in a directory
public static class ExtensionMethod
{
public static void Rename(this FileInfo fileInfo, string newName)
{
fileInfo.MoveTo(fileInfo.Directory.FullName + "\\" + newName + fileInfo.Extension);
}
}
//Caller
FileInfo file = new FileInfo("Complete_Directory_path_of_file");
file.Rename(fName.Replace('/', '-'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment