37 lines
817 B
Bash
37 lines
817 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
# Check for directory argument
|
||
|
if [ -z "$1" ]; then
|
||
|
echo "Usage: $0 /path/to/directory"
|
||
|
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"
|