file size

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
Hello, Hrvoje!

HV> How to get the file size number?

HV> Hrcko

FileInfo fInfo = new FileInfo(filePath);
Console.WriteLine("File size is: " + fInfo.Length.ToString());

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
Hrvoje Voda,
I believe there is more than one way to do that, but check out
FileInfo.Length proeprty.
 
It works, but I want to get a value in KB.
Example, I get 8745 bytes, but I also want to get a value in KB.
 
I don't get a decimal number, just rounded number.

For example, number is 8735, and I want to get 8,735.
 
Due to internationalisation, I'm not 100% sure whether you mean "8 <thousand
separator> 735" or "8 <decimal point> 735"

For the former, something like fileSize.ToString("###,###,##0"); might help

For the latter, try fileSize / 1000F;

Hope this helps,

Marc
 
Hrvoje Voda said:
I don't get a decimal number, just rounded number.

For example, number is 8735, and I want to get 8,735.

That's because unless you specify anything different, C# will divide
one integer by another in an integer way.

You can use fileSizeInBytes / 1024.0 to get a binary floating point
number, or fileSizeInBytes / 1024m to get a decimal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

form size 1
print picture 2
pdf files 1
without extension 2
file path 2
sort string 10
read jpg file 2
listview 3

Back
Top