[Pythonmac-SIG] os.path.getsize()

JoanCarles p Casasín joanca@typerware.com
Tue, 29 Feb 2000 18:19:11 +0100


Nils Kassube wrote:

>Guten Abend.
>
>I hope, I don't miss something obvious again :-)

>--cut--
>>>> import os.path
>>>> os.path.getsize("a.py")
>Traceback (innermost last):
>  File "<stdin>", line 1, in ?
>  File "Macintosh HD:Programme:Python 1.5.2c1:Lib:macpath.py", line 107, 
>in getsize
>    return st[stat.ST_SIZE]
>NameError: stat
>--cut--

Many many time ago Jack Jansen answered this question to me:

----------------------------------
Jack Jansen:

There are a few ways to do this, depending on what you're interested
in. If you want to get the size of the data fork only the best method
is os.stat(). The sixth value is the size of the data fork. This
method is portable to other platforms.

If you want the full size use os.xstat(). rv[6] is again data fork
size, rv[10] is the resource fork size. xstat is mac-specific.

You can also use the GetFInfo() method of a macfs.FSSpec object, if
that is handier. Again, mac-specific.

Note that all these methods give you the number of bytes in the file,
*not* the amount of space it occupies on disk (the finder info command 
gives both). Does anyone know how to obtain the diskspace numbers?
----------------------------------

>What's wrong? It worked on Win32.

You're now using a Mac! ;)


JoanCarles


:::!!!:::
joanca@typerware.com

http://www.typerware.com