开发者

Python Directory Display in Finder, Explorer, Dolphin, etc... (Cross-Platform)

开发者 https://www.devze.com 2023-01-14 05:21 出处:网络
I would like to find some way of Viewing a Directory in the default file system viewer (Windows Explorer, Finder, Dolphin, etc...) tha开发者_JAVA技巧t will work on all major platforms.

I would like to find some way of Viewing a Directory in the default file system viewer (Windows Explorer, Finder, Dolphin, etc...) tha开发者_JAVA技巧t 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?


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消