os

os.path.sep 路径分隔符 linux下就用这个了’/’
os.path.altsep 根目录
os.path.curdir 当前目录
os.path.pardir 父目录
os.path.abspath(path) 绝对路径
os.path.join() 常用来链接路径
os.path.split(path) 把path分为目录和文件两个部分,以列表返回
import os
for root, dirs, files in os.walk("fly", topdown=False):
    for name in files:
        print(os.path.join(root, name))
    for name in dirs:
        print(os.path.join(root, name))

 该函数返回一个元组,该元组有3个元素,这3个元素分别表示每次遍历的路径名,目录列表和文件列表

原文地址:https://www.cnblogs.com/jzm17173/p/5201725.html