我目前的做法是使用一组类来定义每个目录及其文件,如下所示:
import sys
import os
class HDD():
global Child, Parent, Type
Child = ["Direcory1", "File1.txt"]
Parent = "Computer"
Type = "Local Drive"
File1_txt = ["Hello World", "Read"]
class Directory1():
global Child, Parent, Type
Child = ["File1.txt", "File2.txt"]
Parent = "HDD"
Type = "Dir"
File1_txt = ["Hello World Again...", "Read"]
File2_txt = ["Hello World Again...", "Read"]
CurrentDirectory = HDD
while True:
global Command, Split, CurrentDirectory
Command = input(CurrentDirectory+">")
if "dir" in Command:
for Return in CurrentDirectory.Child:
print(Return+" ["+CurrentDirectory.Type+"]")
当我使用dir
命令时,我需要它来使用CurrentDirectory但是参考类HDD,是否有办法使这项工作,或使整个事情更有效?
注意:我正在尝试为游戏制作Windows命令行的副本,而这正在处理Python中的Windows文件系统。