Skip to content

Commit 9276650

Browse files
committed
Include folder path, filename, and file suffix columns in CSV result
1 parent e04e60f commit 9276650

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import argparse
2222
import csv
2323
import os
24+
import pathlib
2425

2526

2627
def get_file_paths_within_folder(path_to_folder):
@@ -101,9 +102,17 @@ def main(path_to_folder, path_to_csv_file, path_to_output_file=None, log_level=l
101102
if type(path_to_output_file) is str:
102103
with open(path_to_output_file, 'w', encoding='utf-8', newline='') as f:
103104
writer = csv.writer(f)
104-
header_row = [f"File path"]
105+
106+
# Populate the header row (i.e. column names).
107+
header_row = ["File", "Folder", "Filename", "Suffix (only)"]
105108
writer.writerow(header_row)
106-
data_rows = [[path] for path in sorted_differences] # result has the shape: `[ [path_1], [path_2], ... ]`
109+
110+
# Populate the data rows with the file path, folder path (no filename), filename, and file suffix.
111+
data_rows = []
112+
for path in sorted_differences:
113+
file_suffix = pathlib.Path(path).suffix
114+
(folder_path, filename) = os.path.split(path)
115+
data_rows.append([path, folder_path, filename, file_suffix])
107116
writer.writerows(data_rows)
108117
else:
109118
print('\n'.join(sorted_differences))

0 commit comments

Comments
 (0)