Skip to content

Commit 1461479

Browse files
Merge pull request geekcomputers#177 from EroMonsterSanji/dir_test
python3 compatibility for dir_test.py
2 parents bf78ecd + 11e5e91 commit 1461479

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

dir_test.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77

88
# Description : Tests to see if the directory testdir exists, if not it will create the directory for you
99
from __future__ import print_function
10-
import os #Import the OS Module
11-
CheckDir = raw_input("Enter the name of the directory to check : ")
12-
print
13-
if os.path.exists(CheckDir):#Checks if the dir exists
14-
print("The directory exists")
15-
else:
16-
print("No directory found for "+CheckDir) #Output if no directory
17-
print
18-
os.makedirs(CheckDir)#Creates a new dir for the given name
19-
print("Directory created for "+CheckDir)
10+
import os # Import the OS Module
11+
import sys
12+
13+
14+
def main():
15+
if sys.version_info.major >= 3: # if the interpreter version is 3.X, use 'input',
16+
input_func = input # otherwise use 'raw_input'
17+
else:
18+
input_func = raw_input
19+
20+
CheckDir = input_func("Enter the name of the directory to check : ")
21+
print()
22+
23+
if os.path.exists(CheckDir): # Checks if the dir exists
24+
print("The directory exists")
25+
else:
26+
print("No directory found for " + CheckDir) # Output if no directory
27+
print()
28+
os.makedirs(CheckDir) # Creates a new dir for the given name
29+
print("Directory created for " + CheckDir)
30+
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)