Created
March 5, 2018 10:19
-
-
Save abhaydhar/ad1ab0447681de279722c9a419063f73 to your computer and use it in GitHub Desktop.
Extension Method to Rename a file in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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