473,387 Members | 1,664 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,387 software developers and data experts.

Determining File Size In Code

Hi,

It looks like the only way to get a size of a file within dot net is to
use FileInfo and the Length property. However that only returns the
number of bytes in the file which is translating properly (I have a
file that has a size of 1 KB but has 14 bytes in it so the conversion
isn't working right). Is there some method/property out there that
will get the actual size of the file? Also, would there be a method
like this that will get this size of a file that is being written to?
(I need to write data to a file but need to track how big the file is
getting as I'm writing it.)

Oct 4 '06 #1
2 1539
>Is there some method/property out there that
>will get the actual size of the file?
You are getting the actual size of the file. The number in Windows Explorer
is just rounded up. I tried this myself, and at 1024 bytes, the file size
reads 1KB in Explorer. At 1025, it's 2. So you need to do your conversion
based on the same type of rounding.

As for reading it from a file that's being written, I think this will work
if you call the Flush() method of the StreamWriter and then do your size
check.
Oct 4 '06 #2
The rounding up was kind of what I was coming around to as well as I
was posting this. Thanks for the suggestions, I will give them a try!

Oct 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
2
by: Phil Galey | last post by:
In VB.NET I find the IO object very handy in replacing most of the functionality of the FileSystemObject. One exception, however, is in determining the size of a file. How can you determine the...
12
by: Raja | last post by:
How to know the buffer size and increase buffer size in c++.
4
by: Jozef | last post by:
Hello, I'd like to determine the size of a file via a URL. I'm not even sure how to do this on the local machine, let alone a URL. Any help would be greatly appreciated. Thanks!
10
by: Orion | last post by:
Hey, I was wondering if it was possible to determine if you hit 'EOF' using fseek? I'm using fseek to traverse through the file from start to end and capturing the data into a linked list...
14
by: googler | last post by:
Is there any C library function that returns the size of a given file? Otherwise, is there a way in which file size can be determined in a C program? I need to get this for both Linux and Windows...
9
by: vineeth | last post by:
Hello all, I have come across a weird problem, I need to determine the amount of bytes read from a file, but couldn't figure it out , My program does this : __ file = open("somefile") data =...
4
by: steven | last post by:
hi i've got an app that runs something like 4000 updates when certain pages are updated. it's taking on average 20 seconds for these pages to execute the update command (15 seconds if all i do...
38
Frinavale
by: Frinavale | last post by:
I'm implementing a Silverlight application that uses Sockets to receive data that is pushed to it from a Socket Server. (Silverlight only supports the TCP protocol) The Socket Server pushes a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.