-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_files.py
51 lines (41 loc) · 1.7 KB
/
check_files.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
import os
import sys
import argparse
import datetime
import pprint
from glob import glob
def main():
description = 'SDOML-lite, file inspector'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--source_dir', type=str, help='Source directory', required=True)
parser.add_argument('--min_size', type=int, default=20000, help='Threshold for minimum file size (bytes)')
parser.add_argument('--max_size', type=int, default=10000000, help='Threshold for maximum file size (bytes)')
parser.add_argument('--pattern', type=str, default='*', help='File pattern to match')
args = parser.parse_args()
print(description)
start_time = datetime.datetime.now()
print('Start time: {}'.format(start_time))
print('Arguments:\n{}'.format(' '.join(sys.argv[1:])))
print('Config:')
pprint.pprint(vars(args), depth=2, width=50)
print()
files_processed = 0
files_reported = 0
for file_path in glob(os.path.join(args.source_dir, '**', args.pattern), recursive=True):
if not os.path.isfile(file_path):
continue
files_processed += 1
size = os.path.getsize(file_path)
if size < args.min_size:
files_reported += 1
print('File: {} Size: {:,}'.format(file_path, size))
elif size > args.max_size:
files_reported += 1
print('File: {} Size: {:,}'.format(file_path, size))
print()
print('Files processed: {}'.format(files_processed))
print('Files reported : {}'.format(files_reported))
print('End time: {}'.format(datetime.datetime.now()))
print('Duration: {}'.format(datetime.datetime.now() - start_time))
if __name__ == '__main__':
main()