-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermi
45 lines (35 loc) · 1.07 KB
/
termi
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
39
40
41
42
43
44
#!/bin/bash
# Check if a file is provided as an argument
if [ $# -ne 1 ]; then
echo "Usage: $0 directory_structure.txt"
exit 1
fi
# Read the file
file=$1
# Initialize variables
current_path=""
path_stack=()
counter = 0
# Read the file line by line
while IFS= read -r line; do
# Remove leading spaces and ├──, └──, ── characters
line_clean=$(echo "$line" | sed 's/[│├└── ]*//g')
# Determine the depth level (number of leading spaces / 4)
depth=$(echo "$line" | sed -e 's/[^ ]//g' | wc -c)
depth=$((depth / 4))
# Adjust the current path stack
while [ ${#path_stack[@]} -gt $depth ]; do
unset path_stack[${#path_stack[@]}-1]
done
# Append the cleaned line to the current path
path_stack+=("$line_clean")
full_path=$(IFS=/; echo "${path_stack[*]}")
# If the line ends with a slash, it's a directory
if [[ "$line" == */ ]]; then
mkdir -p "$full_path"
else
# Otherwise, it's a file
touch "$full_path"
fi
done < "$file"
echo "Directory structure created successfully."