Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoWorms authored Nov 16, 2023
1 parent 5964420 commit 0d18f46
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions concat.py
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')

0 comments on commit 0d18f46

Please sign in to comment.