Skip to content

Instantly share code, notes, and snippets.

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);
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