Python遍历指定文件夹下所有文件or文件夹

Python遍历指定文件夹下所有文件or文件夹

shell指令

#shell指令
find $NAME -type f 
find $NAME -type d

Python源码

# real_path: $NAME
for dir_name, _, file_names in os.walk(real_path):
    
    # 1. Full directory.
    print (dir_name)
    
    # 2. Full path.
    for file_name in file_names:
        print (os.path.join(dir_name, file_name))

 

你可能感兴趣的:(Python)