سلام خدمت تمامی دوستان
من می خواستم تو محیط کنسول سی شارپ اندازه یه فایل که مسیرش مشخص شده رو بدست بیارم ولی موندم چکار کنم؟؟؟
Printable View
سلام خدمت تمامی دوستان
من می خواستم تو محیط کنسول سی شارپ اندازه یه فایل که مسیرش مشخص شده رو بدست بیارم ولی موندم چکار کنم؟؟؟
سلام ،
شما باید از کلاس System.IO.FIleInfo و پروپرتی Length مربوط به آن استفاده نمایید که اندازه فایل را بر حسب بایت برمیگرداند.
مثالی از MSDN :
// The following example displays the names and sizes
// of the files in the specified directory.
using System;
using System.IO;
public class FileLength
{
public static void Main()
{
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("c:\\");
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();
// Display the names and sizes of the files.
Console.WriteLine("The directory {0} contains the following files:", di.Name);
foreach (FileInfo f in fiArr)
Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length);
}
}