Skip to content

Instantly share code, notes, and snippets.

@maftieu
maftieu / gist:f5c8f18488fcf6f3112b
Last active August 29, 2015 14:11
C# - Changes the extension of a file
/// <summary>
/// Changes the file extension by moving it.
/// </summary>
/// <param name="filePath">Full path to the file for which change the extension.</param>
/// <param name="extension">The new file extension.</param>
/// <returns>The path to the file, with the new extension.</returns>
private string ChangeFileExtension(string filePath, string extension)
{
if (!extension.StartsWith("."))
extension = "." + extension;
@maftieu
maftieu / gist:9a3d1532aa968e68f6a2
Last active August 29, 2015 14:11
C# - FormatFileSize
static string FormatFileSize(long value, string format = null)
{
var multipliers = new string[] { "o", "Kio", "Mio" };
var midx = 0;
while ((Math.Abs(value) >= 1024) && (midx < multipliers.Length))
{
value /= 1000;
++midx;
}