-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistfile.py
More file actions
75 lines (62 loc) · 1.84 KB
/
Copy pathlistfile.py
File metadata and controls
75 lines (62 loc) · 1.84 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
70
71
72
73
74
75
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, os, os.path, re
import optparse
VERSION = '1.0'
if __name__ == '__main__':
parser = optparse.OptionParser(
usage="%prog [options] <directory> [<directory> ...]\n"
"List files under specified directory.",
version="%s" % VERSION
)
parser.add_option(
"-e", "--excludefile",
action="store", type="string", dest="exclude",
default=None,
help="Specify file written exclude files. The default value for this option is '%default'."
)
parser.add_option(
"-a", "--absdisp",
action="store_true", dest="abstruct",
default=False,
help="When this option specified, output file with abspath. The default value for this option is '%default'."
)
parser.add_option(
"-p", "--pattern",
action="store", type="string", dest="pattern",
default="\.cue$",
help="Specify pattern for filename. pattern is regexp. The default value for this option is '%default'."
)
# Parse command-line arguments.
(options, args) = parser.parse_args()
# file check
if(options.exclude is not None and not os.path.isfile(options.exclude)):
sys.stderr.write("exclude file not found.")
sys.exit(1)
flist = []
for arg in args:
for current, dirs, files in os.walk(arg):
for file in files:
if re.search(options.pattern, file) is not None:
path = ""
if options.abstruct:
path = os.path.join(os.path.abspath(current), file)
else:
path = os.path.join(current, file)
flist.append(path)
excludes = []
if options.exclude is not None:
f = open(options.exclude, 'r')
for line in f:
line = line.rstrip()
if line.startswith("#"):
continue
if options.abstruct:
excludes.append(os.path.abspath(line))
else:
excludes.append(line)
f.close()
set_file = set(flist)
set_file.difference_update(set(excludes))
for file in set_file:
print file