-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextFind.py
executable file
·51 lines (46 loc) · 1.76 KB
/
extFind.py
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
#!/ccnc_bin/venv/bin/python
from ccncpy import *
def main(args):
if not args.count:
for i in extSearch(args.extension,args.inputDir):
print i
else:
df = dict2pd(countExt(args.extension,args.inputDir))
if args.output.endswith('xls'):
df.to_excel(args.output)
elif args.output.endswith('txt'):
df.to_csv(args.output,sep='\t')
elif args.output.endswith('csv'):
df.to_csv(args.output)
else:
print df
if __name__ == '__main__':
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
{codeName} : Search files with user defined extensions
========================================
eg) {codeName} -e 'dcm|ima' -i /Users/kevin/NOR04_CKI
Search dicom files in /Users/kevin/NOR04_CKI
eg) {codeName} -c -e 'dcm|ima' -i /Users/kevin/NOR04_CKI
Count dicom files in each directory under input
'''.format(codeName=os.path.basename(__file__))))
parser.add_argument(
'-i', '--inputDir',
help='Data directory location, default=pwd',
default=os.getcwd())
parser.add_argument(
'-c', '--count',
help='count files with the ext in each directory',
action='store_true')
parser.add_argument(
'-o', '--output',
default='print',
help='Eg. output.xlsx. Output types, [xls,csv,txt]. If not specified, just prints')
parser.add_argument(
'-e', '--extension',
help='Extension to search')
args = parser.parse_args()
if not args.extension:
parser.error('No extension given, add -e or --extension')
main(args)