-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5964420
commit 0d18f46
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
# Function to concatenate files into a single .txt file | ||
def concatenate_files(dir_name, output_filename): | ||
with open(output_filename, 'w', encoding='utf-8') as output_file: | ||
for root, dirs, files in os.walk(dir_name): | ||
for file in files: | ||
if file.endswith('.lock'): # Ignore large files that adds nothing to overall knowledge | ||
continue | ||
file_path = os.path.join(root, file) | ||
try: | ||
with open(file_path, 'r', encoding='utf-8') as f: | ||
output_file.write('######## ' + file_path + '\n\n') | ||
output_file.write(f.read() + '\n\n') | ||
except Exception as e: | ||
print(f"Skipping non-text file or error reading file: {file_path} - {e}") | ||
|
||
# Example Call | ||
concatenate_files('./knowledge-base', 'knowledge-base.txt') |