File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # encoding: utf-8
3+
4+ """
5+ @author: zhanghe
6+ @software: PyCharm
7+ @file: test_file.py
8+ @time: 16-1-9 上午11:24
9+ """
10+
11+ import os
12+ import os .path
13+
14+ root_dir = '/tmp' # 指明被遍历的文件夹
15+
16+ for dir_parent , dir_names , file_names in os .walk (root_dir ): # 三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
17+ for dir_name in dir_names : # 输出文件夹信息
18+ print "dir_parent is:" + dir_parent
19+ print "dir_name is" + dir_name
20+
21+ for file_name in file_names : # 输出文件信息
22+ print "dir_parent is:" + dir_parent
23+ print "file_name is:" + file_name
24+ print "the full name of the file is:" + os .path .join (dir_parent , file_name ) # 输出文件路径信息
25+
26+ # 获取指定目录下的所有文件和目录名,列表形式
27+ print os .listdir (root_dir )
28+
29+ root_dir = '/tmp'
30+ for file_name in [item for item in os .listdir (root_dir ) if item .startswith ('resume-' ) and item .endswith ('.html' )]:
31+ file_path = os .path .join (root_dir , file_name )
32+ print file_path
33+ with open (file_path , 'rb' ) as f :
34+ html = f .read ().decode ('utf-8' )
35+ print html
36+
37+
38+ if __name__ == '__main__' :
39+ pass
You can’t perform that action at this time.
0 commit comments