码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2021-04-14 11:51:07      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:pytho   port   main   getpath   目录   打印   imp   file   roo   

#!/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.walk(root.file))

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

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

标签:pytho   port   main   getpath   目录   打印   imp   file   roo   

原文地址:https://www.cnblogs.com/yx-book/p/14653244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!