473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

file size

How to get the file size number?

Hrcko
Feb 7 '06 #1
9 3866
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
4
by: M P | last post by:
Can you help me find an asp code that will upload a file from my PC to web server? Mark
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
2
by: Dan | last post by:
Hi, I know this code is not entirely javascript, but bare with me. Can you please tell me why this does not work: page: filemanager.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: cleary1981 | last post by:
Hi, I have created a script in PHP thats generates an SVG image. Want I want to do is have PHP save this as example.svg. Can this be done? Heres my code <?php require "config.php"; $proj_id =...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.