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?
views:
18answers:
1
+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
2010-09-01 15:57:29
Is the Unix compatible with Linux (dumb question, I know), and is it compatible with all distros?
CMC
2010-09-01 16:01:50
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
2010-09-01 16:11:13