Python os 备查

path = './test/'
# 创建路径
def mkdir(path):
    if not os.path.exists(path):
        os.makedirs(path)
# 查文件列表
os.listdir(path)
# 判断是否为文件夹
os.path.isdir(path)
# 判断是否为文件
os.path.isfile(path)

# 判断路径是否存在
os.path.exists(path)
# 路径拼接
os.path.join(path, 'test/test')
# 获取文件夹名
dir = os.path.dirname(path)
# 重命名文件
os.rename('文件1','文件2')
posted @ 2021-05-14 15:04  太晓  阅读(34)  评论(0编辑  收藏  举报