Skip to content

Commit c3f4447

Browse files
Merge pull request geekcomputers#168 from nnamdiib/patch-3
Refactor hard-coded values to allow flexibility.
2 parents cc99f74 + 8c220e7 commit c3f4447

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

create_dir_if_not_there.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
# Description : Checks to see if a directory exists in the users home directory, if not then create it
1010

1111
import os # Import the OS module
12+
MESSAGE = 'The directory already exists.'
13+
TESTDIR = 'testdir'
1214
try:
13-
home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory
14-
print(home) # Print the location
15-
16-
if not os.path.exists(os.path.join(home, 'testdir')): # os.path.jon() for making a full path safely
17-
os.makedirs(os.path.join(home, 'testdir')) # If not create the directory, inside their home directory
15+
home = os.path.expanduser("~") # Set the variable home by expanding the user's set home directory
16+
print(home) # Print the location
17+
18+
if not os.path.exists(os.path.join(home, TESTDIR)): # os.path.join() for making a full path safely
19+
os.makedirs(os.path.join(home, TESTDIR)) # If not create the directory, inside their home directory
20+
else:
21+
print(MESSAGE)
1822
except Exception as e:
1923
print(e)
24+

0 commit comments

Comments
 (0)