我刚开始接触Python,但已经发现它比Bash shell脚本更有效率了。
我正在尝试编写一个Python脚本,它将遍历从我启动脚本的目录分支出的每个目录,并对遇到的每个文件加载此类的实例:
class FileInfo:
def __init__(self, filename, filepath):
self.filename = filename
self.filepath = filepath
filepath 属性将是从根目录 (/) 开始的完整绝对路径。这是我想要主程序执行的伪代码模型:
from (current directory):
for each file in this directory,
create an instance of FileInfo and load the file name and path
switch to a nested directory, or if there is none, back out of this directory
我一直在阅读有关os.walk()和ok.path.walk()的内容,但我想知道在Python中实现这个功能最简单的方法是什么。谢谢。