Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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