Created
January 7, 2022 08:53
-
-
Save cacapon/e2fcf366264612a46a01b3c294498d36 to your computer and use it in GitHub Desktop.
pythonで作成したディレクトリシステムの試作品
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dir_data = { | |
'/': [ | |
'basic/', | |
'plus/' | |
], | |
'/basic/': [ | |
'what/', | |
'whom/', | |
], | |
'/basic/what/': [ | |
'damage/', | |
'accel/', | |
'defup/', | |
], | |
'/basic/what/damage/': [ | |
'white.pt', | |
'pouple.pt', | |
'red.pt', | |
'blue.pt', | |
'green.pt', | |
'yellow.pt', | |
'brown.pt', | |
], | |
'/basic/what/accel/': [ | |
'white', | |
'pouple', | |
'red', | |
'blue', | |
'green', | |
'yellow', | |
'brown', | |
], | |
'/basic/what/defup/': [ | |
'white', | |
'pouple', | |
'red', | |
'blue', | |
'green', | |
'yellow', | |
'brown', | |
], | |
'/basic/whom/': [ | |
'me/', | |
'you/', | |
], | |
'/basic/whom/me/': [ | |
'white', | |
'pouple', | |
'red', | |
'blue', | |
'green', | |
'yellow', | |
'brown', | |
], | |
'/basic/whom/you/': [ | |
'white', | |
'pouple', | |
'red', | |
'blue', | |
'green', | |
'yellow', | |
'brown', | |
], | |
'/plus/': [ | |
'p+/', | |
'q+/', | |
'm+/', | |
] | |
} | |
path = '/' | |
def cd(next_path): | |
# 指定したパスに移動する | |
global path | |
if next_path == '..': | |
path = '/' # 普通のcdとは違うけど、一番上に戻るようにする | |
else: | |
if path + next_path in dir_data: | |
path += next_path | |
else: | |
print('{}は存在しません'.format(path + next_path)) | |
def ll(): | |
# pathの中身を表示する | |
data = dir_data[path] | |
for i in data: | |
print(i) | |
def pwd(): | |
# 現在のパスを表示する | |
print(path) | |
def main(): | |
while True: | |
cmd = input('cmd?>').split(' ') | |
if cmd[0] == 'cd': | |
cd(cmd[1]) | |
if cmd[0] == 'll': | |
ll() | |
if cmd[0] == 'pwd': | |
pwd() | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment