Python 打印目录和目录下所有文件


#!/usr/bin/env python3
#!-*- coding:UTF-8 -*-

import os
class GetPath():# 获取所有目录
@staticmethod
def get_dir(path):
print("打印所有目录:")
for root, dirs, files in os.walk(path):
for dir in dirs:
print(os.path.join(root,dir))

@staticmethod
def get_file(path): # 获取文件路径
print("所有文件路径是:")
for root, dirs, files in os.walk(path):
for file in files:
print(os.path.join(root,file))

if __name__ == '__main__':
path="/opt"
GetPath.get_dir(path)
GetPath.get_file(path)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM