Tim Michelsen | 15 May 20:08
Picon

Open a directory in the default file manager

Hello,
is there any function/module that allows me to open a directory in the 
default file manager of a operating system?

Here I a piece of code how to open a URL in the default webbrowser:

http://www.python.org/doc/lib/module-webbrowser.html

import webbrowser
myurl = 'http://www.python.org'
webbrowser.open_new_tab(myurl)

I just wanna do the same with a directory.

The function should open Explorer on Windows, Nautilus on Gnome, Thunar 
onn XFCE4, ...

Thanks for your help in advance.

Regards,
Timmie

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Thomas Pani | 16 May 17:55
Picon

Re: Open a directory in the default file manager

Tim Michelsen wrote:
 > Hello,
 > is there any function/module that allows me to open a directory in the
 > default file manager of a operating system?

On Windows you can use os.startfile().
On "pure" Unices there's no such thing as filetype associations
However, if you use a desktop environment, you can spawn xdg-open (from 
xdg-utils) from Python. This will autodetect gnome, kde and xfce and use 
their tools (gnome-open, kfmclient, exo-open).
I think on OS X/Darwin there's a similar utility called `open'.

You can use sys.platform to determine which system you're running on.

thomas
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Tim Michelsen | 19 May 21:36
Picon

Re: Open a directory in the default file manager

Hi!

>  > is there any function/module that allows me to open a directory in the
>  > default file manager of a operating system?
> 
> On Windows you can use os.startfile().
> On "pure" Unices there's no such thing as filetype associations
> However, if you use a desktop environment, you can spawn xdg-open (from 
> xdg-utils) from Python. This will autodetect gnome, kde and xfce and use 
> their tools (gnome-open, kfmclient, exo-open).
> I think on OS X/Darwin there's a similar utility called `open'.
> 
> You can use sys.platform to determine which system you're running on.
I wasn't able to start explorer with os.startfile()

I then used
subprocess.call(['explorer', my_directory])

And it works.

Kind regards,
Timmie

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane