469,299 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

file size

How to get the file size number?

Hrcko
Feb 7 '06 #1
9 3803
Hrvoje Voda,
I believe there is more than one way to do that, but check out
FileInfo.Length proeprty.
--
HTH
Stoitcho Goutsev (100)

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:ds**********@ss405.t-com.hr...
How to get the file size number?

Hrcko

Feb 7 '06 #2
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
Feb 7 '06 #3
"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:ds**********@ss405.t-com.hr...
How to get the file size number?


You can use System.IO.FileInfo.Length

/Anders
Feb 7 '06 #4
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.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Hrvoje Voda,
I believe there is more than one way to do that, but check out
FileInfo.Length proeprty.
--
HTH
Stoitcho Goutsev (100)

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:ds**********@ss405.t-com.hr...
How to get the file size number?

Hrcko


Feb 7 '06 #5
So divide by 1000 or 1024 depending on your local interpretation of KB...

Marc
Feb 7 '06 #6
Hello, Hrvoje!

divide the size on 1024

int kbSize = fileInfo.Length / 1024;

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 7 '06 #7
I don't get a decimal number, just rounded number.

For example, number is 8735, and I want to get 8,735.
"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
Hello, Hrvoje!

divide the size on 1024

int kbSize = fileInfo.Length / 1024;

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Feb 8 '06 #8
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

Feb 8 '06 #9
Hrvoje Voda <hr*********@luatech.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 8 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Skc | last post: by
1 post views Thread by BW | last post: by
2 posts views Thread by Dan | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.