-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetFileCreated.py
More file actions
42 lines (38 loc) · 1.66 KB
/
GetFileCreated.py
File metadata and controls
42 lines (38 loc) · 1.66 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
import os
import json
import sys
def extract_files_created(report_path):
total_files_created = 0
files_created = []
try:
with open(report_path, 'r') as report_file:
report_data = json.load(report_file)
target_filename = report_data["target"]["file"]["name"]
behavior = report_data.get('behavior', {})
summary = behavior.get('summary', {})
files_created = summary.get('file_created', [])
total_files_created = len(files_created)
except Exception as e:
print(f"Error processing {report_path}: {e}")
return total_files_created, files_created, target_filename
def traverse_directory(directory_path):
total_files_created_overall = 0
for root, dirs, files in os.walk(directory_path):
for file in files:
if file == 'report.json':
report_path = os.path.join(root, file)
total_files_created, files_created, target_filename = extract_files_created(report_path)
if files_created:
total_files_created_overall += total_files_created
print(f"\nFiles created by {target_filename} at {report_path}:")
for file_name in files_created:
print(file_name)
else:
print(f"\nNo files created by {target_filename} at {report_path}")
print(f"\nTotal number of files created: {total_files_created_overall}")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <directory_path>")
sys.exit(1)
directory_path = sys.argv[1]
traverse_directory(directory_path)