Skip to content

Commit c87e6f6

Browse files
committed
added exceptions
1 parent ee9ff4b commit c87e6f6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

create_dir_if_not_there.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Script Name : create_dir_if_not_there.py
22
# Author : Craig Richards
33
# Created : 09th January 2012
4-
# Last Modified :
4+
# Last Modified : 22nd October 2015
55
# Version : 1.0
6-
# Modifications :
6+
# Modifications : Added exceptions
77

88
# Description : Checks to see if a directory exists in the users home directory, if not then create it
99

10-
import os # Import the OS module
11-
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
12-
print home # Print the location
13-
if not os.path.exists(home+'/testdir'): # Check to see if the directory exists
14-
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
10+
import os # Import the OS module
11+
try:
12+
home=os.path.expanduser("~") # Set the variable home by expanding the users set home directory
13+
print home # Print the location
14+
if not os.path.exists(home+'/testdir'):
15+
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
16+
except Exceptions as e:
17+
print e

0 commit comments

Comments
 (0)