Created
February 1, 2016 11:19
-
-
Save yooakim/a60a1351432cf84ceb8a to your computer and use it in GitHub Desktop.
Add timestamp to filename
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 Extensions | |
{ | |
/// <summary> | |
/// Add a timestamp to the filename, before the extension. | |
/// </summary> | |
/// <param name="fileName">any filename for which you want to add a timestamp, including file extension.</param> | |
/// <returns>filename with added timestamp</returns> | |
/// <example> | |
/// <c>var file = "myfile.txt".AddTimeStamp();</c> | |
/// This would return the filename "myfile__20160201120840492.txt" | |
/// </example> | |
public static string AddTimeStamp(this string fileName) | |
{ | |
return string.Concat( | |
Path.GetFileNameWithoutExtension(fileName), | |
DateTime.Now.ToString("_yyyyMMddHHmmssfff"), | |
Path.GetExtension(fileName) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment