Re: [Tutor] Looking for something similar to du...

2008-05-06 Thread Alan Gauld


Marc Tompkins [EMAIL PROTECTED] wrote


Can you explain what you mean by the diffrence between the size
used versus the size of the image?
Disk space is allocated in large units (in DOS/Windows they're 
called

clusters, *nixes call them blocks).


Ah yes, indeed it is. And in a previous life I even used
to care about such things!

Nowadays I've gotten used to disk space being so
cheap and plentiful I confess I'd forgotten all about
the diffrences and their significance.

Thanks for the reminder Marc.

As to finding disk usage on Windows I found this
snippet on an MSDN forum:

--
If you want the size of the file on disk when compressed or sparse
then you have to use Platform/Invoke to call GetCompressedFileSize
as I don't believe .NET exposes this method directly.  Furthermore
this doesn't give you the actual size on disk if it isn't compressed.
For that I believe you'd have to determine how many clusters it
takes up and multiply that by the cluster size.  I don't believe
there is any direct way in Windows to do that but WMI might
provide a way.  Nevertheless this is not what you'd want to
use as it'll also contain unused bytes of data.
-

Which is rather scary...

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for something similar to du...

2008-05-06 Thread Marc Tompkins
On Mon, May 5, 2008 at 11:55 PM, Alan Gauld [EMAIL PROTECTED]
wrote:


 As to finding disk usage on Windows I found this
 snippet on an MSDN forum:

 --
 If you want the size of the file on disk when compressed or sparse
 then you have to use Platform/Invoke to call GetCompressedFileSize
 as I don't believe .NET exposes this method directly.  Furthermore
 this doesn't give you the actual size on disk if it isn't compressed.
 For that I believe you'd have to determine how many clusters it
 takes up and multiply that by the cluster size.  I don't believe
 there is any direct way in Windows to do that but WMI might
 provide a way.  Nevertheless this is not what you'd want to
 use as it'll also contain unused bytes of data.
 -

 Which is rather scary...


Not really, just written by someone who 1) had something else in mind, or 2)
is unclear on the concept.  Because _of course_ this number will include
unused bytes (not of data, though, just of disk space).  It's called
slack space, I believe - all those extra bytes between the end of the file
and the end of the last cluster allocated to the file.  Even with FAT32,
NTFS, and many highly-advanced file systems in the *nix world, it adds up to
a surprisingly large proportion of most peoples' disk space.  (More if you
have lots of tiny files, less if you have lots of big files.)

That being said, I've recently been buying 500GB hard drives for $100.  (And
yes, I'm sure there are even hotter deals out there.  Don't rub it in if
you've found one, though - it'll only make me miserable.)  At 20 cents a
gig, it's hard to work up any real anxiety over slack space.
I'm curious - what does the OP do with this info?  Does it have some deeper
significance I don't know about, or is it just a cool statistic to track?

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for something similar to du...

2008-05-06 Thread Alan Gauld


Marc Tompkins [EMAIL PROTECTED] wrote


As to finding disk usage on Windows I found this
snippet on an MSDN forum:

--

I don't believe

there is any direct way in Windows to do that but WMI might
provide a way.  Nevertheless this is not what you'd want to

Which is rather scary...



Not really, just written by someone who 1) had something else in 
mind,


I just meant the fact that Microsoft didn't appear to provide
an API function to find it directly was scary - especially since
its something they report in Explorer as you noted earlier.


That being said, I've recently been buying 500GB hard
drives for $100.


The cost of disk space is frighteningly cheap.
I remember buying a Terabyte of storage for a mainframe
about 20 years ago and it cost over $2 million. Now I can
buy a Terabyte of NAS for $200!

That's why I've stopped worrying about lost space due to
block sizes! :-)

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for something similar to du...

2008-05-05 Thread Alan Gauld

Spencer Parker [EMAIL PROTECTED] wrote

I am wondering if there is a way to do something that du does in 
Linux.  I
have several disk images and I need a way to get the size used...not 
the
size of the image.  If you type in du and the disk image path it 
gives you

this number.  is there anyway to do this in python?


Probably but I'm not totally clear what you are looking for.
Can you explain what you mean by the diffrence between the size
used versus the size of the image? Surely the size of the image
is the space it uses? Or are you expanding compressed files?

Can you give an example of the two measures so that we(I?) can
better understand the distinction

Meantime try looking at the os.walk function and the os.fstat 
function.

That may be all you need.


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for something similar to du...

2008-05-05 Thread Marc Tompkins
On Mon, May 5, 2008 at 5:21 PM, Alan Gauld [EMAIL PROTECTED]
wrote:

 Probably but I'm not totally clear what you are looking for.
 Can you explain what you mean by the diffrence between the size
 used versus the size of the image? Surely the size of the image
 is the space it uses? Or are you expanding compressed files?


Disk space is allocated in large units (in DOS/Windows they're called
clusters, *nixes call them blocks).  A one-byte file still uses an
entire cluster, whose size depends on the size of the disk and the number of
chunks it can be divided into.  So just knowing the size of the file is not
quite enough information if you need to know how much room is left on the
disk...

If you use Windows, you can see this very easily - right-clicking on a JPEG
file and selecting Properties, I get:
Size: 35.1 KB (35,997 bytes)
Size on disk: 48.0 KB (49,152 bytes)

From the os.stat() docs:

 On some Unix systems (such as Linux), the following attributes may also be
 available: st_blocks (number of blocks allocated for file), 
 st_blksize(filesystem blocksize),
 st_rdev (type of device if an inode device). st_flags (user defined flags
 for file).

So apparently os.stat() can get this info from *nix, but not Windows...
maybe behind the scenes, it runs du?
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Looking for something similar to du...

2008-05-05 Thread Spencer Parker
Mark is right...in that I don't want the actual size of the file
itself...that I can get from another way in Python which i am already
doing.  I was mainly wondering if there was a way to do it and I was just
missing something.  I looked though stat() and that is basically what I
wanted.  I wasn't sure if that was actually it until Mark spelled it out for
me.  I do love using du...since I am learning..I just wanted make sure I
wasn't missing anything...thank you guys as always...


On Mon, May 5, 2008 at 6:57 PM, Marc Tompkins [EMAIL PROTECTED]
wrote:

 On Mon, May 5, 2008 at 5:21 PM, Alan Gauld [EMAIL PROTECTED]
 wrote:

 Probably but I'm not totally clear what you are looking for.
 Can you explain what you mean by the diffrence between the size
 used versus the size of the image? Surely the size of the image
 is the space it uses? Or are you expanding compressed files?


 Disk space is allocated in large units (in DOS/Windows they're called
 clusters, *nixes call them blocks).  A one-byte file still uses an
 entire cluster, whose size depends on the size of the disk and the number of
 chunks it can be divided into.  So just knowing the size of the file is not
 quite enough information if you need to know how much room is left on the
 disk...

 If you use Windows, you can see this very easily - right-clicking on a JPEG
 file and selecting Properties, I get:
 Size: 35.1 KB (35,997 bytes)
 Size on disk: 48.0 KB (49,152 bytes)

 From the os.stat() docs:

 On some Unix systems (such as Linux), the following attributes may also
 be available: st_blocks (number of blocks allocated for file), 
 st_blksize(filesystem blocksize),
 st_rdev (type of device if an inode device). st_flags (user defined flags
 for file).

 So apparently os.stat() can get this info from *nix, but not Windows...
 maybe behind the scenes, it runs du?
 --
 www.fsrtechnologies.com
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
Spencer Parker
___

if you can't go to heaven, may you at least die in Ireland.

___
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor