views:

18

answers:

1

I would like to find some way of Viewing a Directory in the default file system viewer (Windows Explorer, Finder, Dolphin, etc...) that will work on all major platforms. I do not have the detailed knowledge of Linux, nor of OSX in order to write this. Is there some script out there that will do what I want?

+2  A: 

OSX:

os.system('open "%s"' % foldername)

Windows:

os.startfile(foldername)

Unix:

os.system('xdg-open "%s"' % foldername)

Combined:

import os

systems = {
    'nt': os.startfile,
    'posix': lambda foldername: os.system('xdg-open "%s"' % foldername)
    'os2': lambda foldername: os.system('open "%s"' % foldername)
     }

systems.get(os.name, os.startfile)(foldername)
leoluk
Is the Unix compatible with Linux (dumb question, I know), and is it compatible with all distros?
CMC
Linux is a Unix-like system. And yes, it is compatible with all distros if they have xdg-open installed by default (all modern distros).xdg-open is the most compatible way to open folders as there's no generic way to do this as you would need a different approach for every desktop manager.
leoluk