I see this function in the wxWidgets help file, but it does not appear
to be available in wxPython. Is there some other, similar function
available? I know I could do this with win32 api calls, but I was
wondering whether a platform independent method is available. Thanks.
regards, michael
Michael,
From: Michael Moriarity [mailto:datasmith@gmail.com]
Sent: Saturday, October 13, 2007 3:01 PM
To: wxPython-users@lists.wxwidgets.org
Subject: wxGetDiskSpace
I see this function in the wxWidgets help file, but it does
not appear to be available in wxPython. Is there some other,
similar function available? I know I could do this with win32
api calls, but I was wondering whether a platform independent
method is available. Thanks.
regards, michael
You should be able to use the os.stat module to get this information
cross-platform.
http://docs.python.org/lib/os-file-dir.html
http://www.thescripts.com/forum/thread19509.html
You can also use os.path.getsize which is a shortcut that grabs the size
using os.stat (in bytes)
Mike
···
-----Original Message-----
This appears to be one of those problems with no *real* solutions. It
looks like it was discussed on Py-Dev 6 years ago, but I don't see any
resolution to the issue. See link below:
http://mail.python.org/pipermail/python-dev/2001-March/013706.html
Looks to like you get to code it yourself. It sucks though.
I found the following goofy code from some foreign site
(http://gathering.tweakers.net/forum/list_messages/1250001):
size=0
for root, dirs, files in os.walk(".\\filelists\\"):
for name in files:
filename=os.path.join(root,name)
statinfo=os.stat(filename)
print filename, statinfo[6]
size=size+statinfo[6]
print size,"bytes"
The above would probably work, but it would be slow...
On Windows, you can get the free space using Tim Golden's WMI module or
the pywin32 module set.
Other than that, my Google-Fu fails me. Maybe someone else on the list is
smarter than I...in fact, that is quite probable.
Mike
···
-----Original Message-----
From: Michael Moriarity [mailto:datasmith@gmail.com]
Sent: Monday, October 15, 2007 1:36 PM
To: Mike Driscoll
Subject: Re: wxGetDiskSpace
On 10/15/07, Mike Driscoll <mdriscoll@co.marshall.ia.us> wrote:
> Michael,
> You should be able to use the os.stat module to get this
information
> cross-platform.
>
> http://docs.python.org/lib/os-file-dir.html
> Bytes - It's not a glitch, it's a feature!
>
> You can also use os.path.getsize which is a shortcut that grabs the
> size using os.stat (in bytes)
>
> Mike
>
Thanks Mike, but those functions are for getting information
about individual files. What I need is a way to know the
total capacity and free space on a logical disk. Like what df
does in Linux. Any clues on how to do that?
regards, michael
Michael Moriarity wrote:
I see this function in the wxWidgets help file, but it does not appear
to be available in wxPython. Is there some other, similar function
available? I know I could do this with win32 api calls, but I was
wondering whether a platform independent method is available. Thanks.
Here is what I do:
def get_free_space(path = '.'):
"""
Determine the free space in bytes for the given path.
"""
if sys.platform == "win32":
import win32file
sizes = win32file.GetDiskFreeSpace(path)
return sizes[0] * sizes[1] * sizes[2]
else:
import statvfs
stat = os.statvfs(path)
return stat[statvfs.F_BAVAIL] * stat[statvfs.F_FRSIZE]
Carsten.
Mike and Carsten:
Thanks for the suggestions. I guess I'll use Carsten's method.
regards, michael