2024-11-03 19:19:41 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Check for directory argument
|
|
|
|
if [ -z "$1" ]; then
|
2024-11-03 21:25:57 -06:00
|
|
|
echo "Usage: $0 /path/to/directory filename.gmi"
|
2024-11-03 19:19:41 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Define the directory you want to scan
|
|
|
|
DIRECTORY="$1"
|
|
|
|
|
|
|
|
# Output file
|
|
|
|
OUTPUT_FILE="$2"
|
|
|
|
|
|
|
|
# Start the .gmi file
|
|
|
|
echo "# Tree of files in $DIRECTORY" > "$OUTPUT_FILE"
|
|
|
|
echo "" >> "$OUTPUT_FILE"
|
|
|
|
|
|
|
|
# Function to recursively list files
|
|
|
|
list_files() {
|
|
|
|
local dir="$1"
|
|
|
|
local prefix="$2"
|
|
|
|
for file in "$dir"/*; do
|
|
|
|
if [ -d "$file" ]; then
|
2024-11-03 21:25:57 -06:00
|
|
|
echo " ## $prefix${file##*/} ${file##*/}" >> "$OUTPUT_FILE"
|
2024-11-03 19:19:41 -06:00
|
|
|
list_files "$file" "$prefix${file##*/}/"
|
|
|
|
elif [ -f "$file" ]; then
|
|
|
|
echo "=> $prefix${file##*/} ${file##*/}" >> "$OUTPUT_FILE"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call the function
|
|
|
|
list_files "$DIRECTORY" ""
|
|
|
|
|
|
|
|
echo "Tree structure written to $OUTPUT_FILE"
|