dirutility.view.desktop()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 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