-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconcat_files_with_paths.sh
More file actions
executable file
·38 lines (30 loc) · 981 Bytes
/
concat_files_with_paths.sh
File metadata and controls
executable file
·38 lines (30 loc) · 981 Bytes
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
#!/bin/bash
# Check if the src directory exists
if [ ! -d "src" ]; then
echo "The src directory does not exist."
exit 1
fi
# Output file
output_file="concatenated_code.txt"
# Create or clear the output file
> "$output_file"
# Function to concatenate files with path prefix
concatenate_files() {
local dir=$1
# Iterate over all files and directories within the specified directory
for entry in "$dir"/*; do
if [ -f "$entry" ]; then
# Print a separator and the file path at the beginning of each file
echo -e "\n\n--- FILE: $entry ---\n" >> "$output_file"
# Append the file content to the output file
cat "$entry" >> "$output_file"
elif [ -d "$entry" ]; then
# If it's a directory, recursively call this function
concatenate_files "$entry"
fi
done
}
# Start concatenating files from the src directory
concatenate_files "src"
cat README.md >> "$output_file"
echo "All files have been concatenated into $output_file"