Returns a size long - CSharp System.IO

CSharp examples for System.IO:File Size

Description

Returns a size long

Demo Code

/*// w  w  w  .  ja  va 2 s .c  o m
 * $Id: StringUtils.cs 465 2008-10-15 11:53:17Z spocke $
 *
 * Copyright ? 2007, Moxiecode Systems AB, All rights reserved. 
 */
using System.Text.RegularExpressions;
using System.Text;
using System;

public class Main{
        /// <summary>
		///  Returns a size long
		/// </summary>
		/// <param name="size">Size string to convert.</param>
		/// <param name="default_size">Default size string.</param>
		/// <returns>Long representation of the size string.</returns>
		public static long GetSizeLong(string size, string default_size) {
			long sizeInt = 0;
			int pos;

			if (size == null)
				size = default_size;

			size = size.ToLower();

			if ((pos = size.IndexOf("m")) != -1)
				sizeInt = Convert.ToInt64(size.Substring(0, pos)) * (1024 * 1024);
			else if ((pos = size.IndexOf("k")) != -1)
				sizeInt = Convert.ToInt64(size.Substring(0, pos)) * 1024;
			else
				sizeInt = Convert.ToInt64(size);

			return sizeInt;
		}
}

Related Tutorials