Total Complexity | 5 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # View directories and files in a window |
||
2 | import os |
||
3 | from pathlib import Path |
||
4 | from subprocess import call, Popen |
||
5 | from sys import modules |
||
6 | |||
7 | |||
8 | def open_window(path): |
||
9 | """Open path in finder or explorer window""" |
||
10 | if 'pathlib' in modules: |
||
11 | try: |
||
12 | call(["open", "-R", str(Path(str(path)))]) |
||
13 | except FileNotFoundError: |
||
14 | Popen(r'explorer /select,' + str(Path(str(path)))) |
||
15 | else: |
||
16 | print('pathlib module must be installed to execute open_window function') |
||
17 | |||
18 | |||
19 | def desktop(): |
||
20 | try: |
||
21 | home = os.environ['HOMEPATH'] |
||
22 | except KeyError: |
||
23 | home = os.environ['HOME'] |
||
24 | return os.path.join(home, 'Desktop') |
||
25 |