-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir.py
More file actions
25 lines (23 loc) · 838 Bytes
/
dir.py
File metadata and controls
25 lines (23 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# coding=utf-8
import os
import re
def op_dir(order, path):
regex = re.compile(r' *dir +(?:here|/(?P<route>.+)/?) *')
if regex.match(order): # Verifica si hay un match
try:
if regex.match(order).group('route'):
route = regex.match(order).group('route')
if re.match(r'home/.*', route):
path = '/' + route
else:
path = os.getcwd() + '/' + route
os.chdir(path) # si la ruta es valida, la cambia
print "New PATH: " + os.getcwd()
else:
os.chdir(path)
print "Original PATH: " + path # nos devuelve al path original
except OSError:
print "Error: PATH does not exist"
else:
print "Error: Incorrect Command"
return