-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileReader.py
More file actions
62 lines (44 loc) · 1.76 KB
/
Copy pathFileReader.py
File metadata and controls
62 lines (44 loc) · 1.76 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
def read_files_in_directory(directory='.', file_list=None, output_file='fileContents.txt'):
"""Reads all files in a directory and writes the contents to a file.
Args:
- directory (str, optional): The directory to read files from. Defaults to '.'.
- file_list (list, optional): A list of files to read. Defaults to None.
- output_file (str, optional): The file to write the contents to. Defaults to 'fileContents.txt'.
"""
if file_list is None:
return
# Open the output file
with open(output_file, 'w', encoding='utf-8') as f:
# Loop through the files in the list
for file_name in file_list:
# Construct the absolute file path
file_path = os.path.join(directory, file_name)
# Make sure the file exists
if os.path.exists(file_path):
# Open the file with the appropriate encoding
with open(file_path, 'r', encoding='utf-8') as f2:
# Write the contents to the output file
# Title
f.write(f"{file_name}:\n")
# Contents
f.write(f2.read())
# New line
f.write("\n\n")
print(f"✅ '{file_path}' read successfully")
else:
print(f"❌ File '{file_path}' does not exist.")
# Close the output file
f.close()
if __name__ == "__main__":
app_py = "app.py"
nlp_model_py = "NLP_model.py"
index_html = "templates/index.html"
index_css = "static/css/index.css"
index_js = "static/js/index.js"
file_list = [
app_py,
nlp_model_py,
index_html,
]
read_files_in_directory(".", file_list)