This repository was archived by the owner on Jan 29, 2019. It is now read-only.
forked from luozhaohui/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFilenameRecursive.py
More file actions
executable file
·69 lines (56 loc) · 1.92 KB
/
getFilenameRecursive.py
File metadata and controls
executable file
·69 lines (56 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! encoding=utf-8
#!/usr/bin/python
import os
def scan_file(filepath, prefix, output_file):
exclude_extends = ['.mp3', '.jpeg', '.jpg', '.db', '.txt', '.wma', '.nfo']
path = filepath.lower()
for extends in exclude_extends:
if path.endswith(extends):
return
info = '\n{0}- {1}'.format(prefix, os.path.basename(filepath))
output_file.write(info)
# print(info)
def scan_dir(path, prefix, output_file):
info = '\n{0}+ {1}'.format(prefix, os.path.basename(path))
output_file.write(info)
# print(info)
prefix = '{0} '.format(prefix)
for filename in os.listdir(path):
filepath = os.path.join(path, filename)
if os.path.isdir(filepath):
# exclude hidden dirs
if not filename.startswith('.'):
scan_dir(filepath, prefix, output_file)
elif os.path.isfile(filepath):
scan_file(filepath, prefix, output_file)
def scan(path):
output = 'result'
if(os.path.isfile(output)):
os.remove(output)
output_file = open(output, 'a')
prefix = ''
if(os.path.isdir(path)):
scan_dir(path, prefix, output_file)
elif(os.path.isfile(path)):
scan_file(path, prefix, output_file)
output_file.close()
#============================================================================#
scan_path = '/media/luozhaohui/BIGBABY/Movies'
scan(scan_path)
# 输出文件示例如下:
# result
# + 国内电影
# + 我叫刘跃进
# - 我叫刘跃进.rmvb
# + 那山那人那狗
# - 那山那人那狗.rmvb
# + 大红灯笼高高挂
# - 大红灯笼高高挂.rmvb
# + 东邪西毒
# - 东邪西毒.rmvb
# + 平衡
# - [平衡].ping.heng.2001.RMVB-cnjlp.tv.rmvb
# + 租妻
# - 租妻.rmvb
# + 鸡犬不宁
# - [鸡犬不宁].One.Foot.Off.The.Ground.2006.DVDSCR.XviD-CNXP.avi