36 lines
831 B
Bash
Executable file
36 lines
831 B
Bash
Executable file
#!/bin/bash
|
|
|
|
# Check for directory argument
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 /path/to/directory filename.gmi"
|
|
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
|
|
echo " ## $prefix${file##*/} ${file##*/}" >> "$OUTPUT_FILE"
|
|
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"
|