file size on disk

  • Thread starter Thread starter Jim Madsen
  • Start date Start date
J

Jim Madsen

How do you get the "file size on disk" for a file (as opposed to the
file size (length))?
 
Jim,

What is the size of a file, it has only a start point and an end point so
that gives the length in bytes, I did not know that it had more measuring
points.

However, the documentation tells that the fileinfo.length gives back

http://msdn2.microsoft.com/en-us/library/system.io.fileinfo.length(VS.71).aspx
The size of the current file. (Although size is in my idea not the best
description, probably because of the many different meanings of the word
"size" in English, while there is probably not a better word in English for
that)

Cor
 
Jim said:
How do you get the "file size on disk" for a file (as opposed to the
file size (length))?

Round up the file size to the nearest multiple of the size of an allocation
unit (cluster). Now the problem is to find the size of an allocation unit,
which I guess should be available through WMI.

Andrew
 
Well, when you right click on a file and select properties, it gives you
file size, and file size on disk, which is a little bit more. I assume
since Windows spits out these values, there must be an API to get these
values, in worst case.

Jim
 
Jim,

Have a look at the answer from Andrew, however you make me curious, what is
the reason that you want this?

Cor
 
As a learning exercise for myself with vbdotnet, I am writing a program
for my daughter. The requirement is to look for files with three
different file extensions, and group the files with the same name
together. It needs to create subdirectories, copy files with these
extensions to the subdirectories, so that each subdirectory holds just
under the maximum amount that can be copied to a DVD. And if there
isn't room for a group of 3 files, it needs to be copied to the next
subdirectory, rather than just have one or two of the files on the first
subdirectory.

Jim
 
Jim,

Then you have in my idea to calculate how long it will be in bytes in the
target area.

The same again using the method as Andrew wrote using the length and then
the (rounded) size it will then have on the target, I think you have to
learn a lot from it, wmi is very interresting to do, and right in your goal.

There is enough written in this newsgroup about that.

http://groups.google.com/group/micr...net.languages.vb&q=wmi&qt_g=Search+this+group


Cor
 
Jim said:
As a learning exercise for myself with vbdotnet, I am writing a
program for my daughter. The requirement is to look for files with
three different file extensions, and group the files with the same
name together. It needs to create subdirectories, copy files with
these extensions to the subdirectories, so that each subdirectory
holds just under the maximum amount that can be copied to a DVD. And
if there isn't room for a group of 3 files, it needs to be copied to
the next subdirectory, rather than just have one or two of the files
on the first subdirectory.

So you need to find the cluster size for the particular DVD format you want
to write to (DVD-RAM/DVD-R etc), and remember that not quite all the space
is available for data.

If you're filling it to the brim, you may want to zip the files using, e.g.
SharpZipLib
http://www.icsharpcode.net/OpenSource/SharpZipLib/

(Hint: if you use that, make sure to set the .Size of each Entry or else
Windows won't understand the zip file.)

Andrew
 
Have we lost some?
What about the compressed file. I means, the file with "compress" property
checked.
 
Back
Top