How to get list of system drives / folders?

Hi,

not sure if this is a bit offtopic, but maybe anyone in here can help me
anyway.

I have a program which will run on Windows, Mac and Linux. At some part,
a file tree (like the one in Windows Explorer) is displayed. It is
obvious that this file tree would have on Windows the "My Files", the
"Desktop" folder and a number of entries for the drives ("C:", "D:"
etc.). On Linux it maybe would have a pointer to the home folder, plus
the whole tree, which starts with "/".

So I'm having two questions:
1. Is it possible to get a list of "root drives" on the system with
(wx)Python? ("C:"/"D:" on Windows, "/" on Unix, don't know on Mac).
2. Is it possible to get the location of special folders (like the
Desktop folder) with (wx)Python?

It wouldn't be a problem to code this functionality in C using native
system APIs, but since this is Python, I'm afraid that I have to write
some extension module, which I rather would avoid.

Markus

Hi,

not sure if this is a bit offtopic, but maybe anyone in here can help me
anyway.

I have a program which will run on Windows, Mac and Linux. At some part,
a file tree (like the one in Windows Explorer) is displayed. It is
obvious that this file tree would have on Windows the "My Files", the
"Desktop" folder and a number of entries for the drives ("C:", "D:"
etc.). On Linux it maybe would have a pointer to the home folder, plus
the whole tree, which starts with "/".

So I'm having two questions:
1. Is it possible to get a list of "root drives" on the system with
(wx)Python? ("C:"/"D:" on Windows, "/" on Unix, don't know on Mac).

See http://www.faqts.com/knowledge_base/view.phtml/aid/4670/fid/245

2. Is it possible to get the location of special folders (like the
Desktop folder) with (wx)Python?

Under W2K isn't it in C:\Documents and Settings\Administrator\Desktop ?

It wouldn't be a problem to code this functionality in C using native
system APIs, but since this is Python, I'm afraid that I have to write
some extension module, which I rather would avoid.

Presumably you might do something like:

import os

if os.name == 'nt'
...
elif os.name == 'mac'
...import Carbon.Folder

It would probably be best to abstract all this away behind an interface package, with a different implementations for each OS.

···

In message <1073050425.4060.16.camel@markus>, Markus Meyer <meyer@mesw.de> writes:

--
Pythonologist

Markus,

Take a look at wxGenericDirCtrl, which may do what you want (except that it
does not currently work correctly on the Mac).

David Woods
Wisconsin Center for Education Research
University of Wisconsin, Madison

···

-----Original Message-----
From: Markus Meyer [mailto:meyer@mesw.de]
Sent: Friday, January 02, 2004 7:34 AM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython-users] How to get list of system drives / folders?

Hi,

not sure if this is a bit offtopic, but maybe anyone in here can help me
anyway.

I have a program which will run on Windows, Mac and Linux. At some part,
a file tree (like the one in Windows Explorer) is displayed. It is
obvious that this file tree would have on Windows the "My Files", the
"Desktop" folder and a number of entries for the drives ("C:", "D:"
etc.). On Linux it maybe would have a pointer to the home folder, plus
the whole tree, which starts with "/".

So I'm having two questions:
1. Is it possible to get a list of "root drives" on the system with
(wx)Python? ("C:"/"D:" on Windows, "/" on Unix, don't know on Mac).
2. Is it possible to get the location of special folders (like the
Desktop folder) with (wx)Python?

It wouldn't be a problem to code this functionality in C using native
system APIs, but since this is Python, I'm afraid that I have to write
some extension module, which I rather would avoid.

Markus

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

>So I'm having two questions:
>1. Is it possible to get a list of "root drives" on the system with
>(wx)Python? ("C:"/"D:" on Windows, "/" on Unix, don't know on Mac).

See http://www.faqts.com/knowledge_base/view.phtml/aid/4670/fid/245

Many thanks to you and also to David.

wxGenericDirCtrl will definitely do in the beginning, though it is a
pity that it doesn't look more "current" on Windows. It is now really
standard to have a tree that begins with "Desktop" and includes all
those special folders (My Files, My Pictures etc.) as top level entries.
It actually helps newbies to keep track of their files and prevents
people saving stuff in some system folder (by obscurity, not by
permission).

When I write my own control, the FAQ entry you mentioned will sure be
helpful.

>2. Is it possible to get the location of special folders (like the
>Desktop folder) with (wx)Python?

Under W2K isn't it in C:\Documents and Settings\Administrator\Desktop ?

No, the location (and names) of the special folders can vary greatly.
E.g. on an English version of Win98, it could be "C:\Documents", whereas
on a German version of WinXP it would be "C:\Dokumente und
Einstellungen\Username\Eigene Dateien". So there's really not a simple
heuristic to get this location. There's (of course) a Win-API
SHGetSpecialFolder (or something). Maybe I'll write some support
routines and wrap it using SWIG.

Anyway, thanks again.

Markus

···

Am Fre, den 02.01.2004 schrieb Pythonologist um 16:40:

>It wouldn't be a problem to code this functionality in C using native
>system APIs, but since this is Python, I'm afraid that I have to write
>some extension module, which I rather would avoid.

Presumably you might do something like:

import os

if os.name == 'nt'
...
elif os.name == 'mac'
...import Carbon.Folder

It would probably be best to abstract all this away behind an interface package, with a different implementations for each OS.

--
Pythonologist

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

>2. Is it possible to get the location of special folders (like the
>Desktop folder) with (wx)Python?

Under W2K isn't it in C:\Documents and Settings\Administrator\Desktop ?

A few problems there, though. Under W9x and NT, it defaults to a different
place (win*\profiles\user\desktop) instead. Also, using a program like
TweakUI (available from Microsoft), one can CHANGE that location on a
per-user basis (as well as other special folders). As an example, I tend to
set up my own profile's special folders on a non-system drive to make
disaster recovery easier. However, I'm sure there's a system-friendly way to
retrieve the information. MSDN (I kid you not) would be a good place to
start. I *believe* (but am not certain) that you can get this via expansion
of system variables.