Skip to content

Commit c83908f

Browse files
committed
Fixed bug where output would fail if directory didn't exist
1 parent 892c3b8 commit c83908f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/helpers/file_helper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ def __init__(self, output_file):
77
self.output_file = output_file
88

99
def check_directory(self):
10-
directory = self.output_file
10+
directory = os.path.dirname(self.output_file)
11+
1112
try:
12-
os.stat(self.directory)
13+
os.stat(directory)
1314
except:
14-
os.mkdir(self.directory)
15-
print("[!] %s didn't exist and has been created." % output_directory)
15+
os.mkdir(directory)
16+
print("[!] %s didn't exist and has been created." % directory)
1617

1718
# placeholder for error checking on -oJ implementation
1819
def is_json(json_file):
@@ -24,6 +25,9 @@ def is_json(json_file):
2425
return True
2526

2627
def write_file(self, contents):
28+
# check if host directory exists, if not create it
29+
self.check_directory()
30+
2731
with open(self.output_file, "w") as o:
2832
o.write(contents)
2933

0 commit comments

Comments
 (0)