-
Notifications
You must be signed in to change notification settings - Fork 0
/
direc.sh
executable file
·38 lines (29 loc) · 1.19 KB
/
direc.sh
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
# Function to list the directory structure recursively
list_structure() {
local dir="$1"
local indent="$2"
local output_file="$3"
# List and sort the files in the current directory, excluding dotfiles
find "$dir" -maxdepth 1 -type f ! -name '.*' | sort | while IFS= read -r file; do
echo "${indent}├── $(basename "$file")" >> "$output_file"
done
# List and sort the subdirectories in the current directory, excluding dotfiles and node_modules
find "$dir" -maxdepth 1 -type d ! -path "$dir" ! -name '.*' ! -name 'node_modules' | sort | while IFS= read -r subdir; do
echo "${indent}├── $(basename "$subdir")/" >> "$output_file"
list_structure "$subdir" "${indent}│ " "$output_file"
done
}
# Output file
output_file="README1.md"
# Create or clear the output file
: > "$output_file"
# Write the Markdown header and code block start
echo "# Directory Structure" >> "$output_file"
echo "" >> "$output_file"
echo '```' >> "$output_file"
# Start listing from the current directory with no initial indentation
list_structure "." "" "$output_file"
# Write the code block end
echo '```' >> "$output_file"
echo "Directory structure has been saved to $output_file"